mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-04-16 13:13:08 +00:00
std/options fixes
- add Option[T] valueOr/withValue no longer provided by libp2p - add missing std/options imports no longer re-exported by libp2p
This commit is contained in:
parent
7c927c7415
commit
260fb19d81
@ -99,6 +99,9 @@ if not defined(macosx) and not defined(android):
|
||||
nimStackTraceOverride
|
||||
switch("import", "libbacktrace")
|
||||
|
||||
# Shim to provide valueOr and withValue for Option[T]
|
||||
switch("import", "waku/common/option_shim")
|
||||
|
||||
--define:
|
||||
nimOldCaseObjects
|
||||
# https://github.com/status-im/nim-confutils/issues/9
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[sequtils, strutils, net],
|
||||
std/[options, sequtils, strutils, net],
|
||||
stew/byteutils,
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[os, strutils, sequtils, sysrand, math],
|
||||
std/[options, os, strutils, sequtils, sysrand, math],
|
||||
stew/byteutils,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/sequtils,
|
||||
std/[options, sequtils],
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
chronos,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/net,
|
||||
std/[options, net],
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
libp2p/crypto/crypto,
|
||||
|
||||
26
waku/common/option_shim.nim
Normal file
26
waku/common/option_shim.nim
Normal file
@ -0,0 +1,26 @@
|
||||
# Shim to provide valueOr and withValue for Option[T]
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
|
||||
template valueOr*[T](self: Option[T], def: untyped): T =
|
||||
let s = self
|
||||
if s.isSome():
|
||||
s.get()
|
||||
else:
|
||||
def
|
||||
|
||||
template withValue*[T](self: Option[T], value, body: untyped) =
|
||||
let s = self
|
||||
if s.isSome():
|
||||
let value {.inject.} = s.get()
|
||||
body
|
||||
|
||||
template withValue*[T](self: Option[T], value, body, elseStmt: untyped) =
|
||||
let s = self
|
||||
if s.isSome():
|
||||
let value {.inject.} = s.get()
|
||||
body
|
||||
else:
|
||||
elseStmt
|
||||
Loading…
x
Reference in New Issue
Block a user