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:
Fabiana Cecin 2026-03-26 23:41:05 -03:00
parent 7c927c7415
commit 260fb19d81
No known key found for this signature in database
GPG Key ID: BCAB8A55CB51B6C7
6 changed files with 33 additions and 4 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[sequtils, strutils, net],
std/[options, sequtils, strutils, net],
stew/byteutils,
testutils/unittests,
chronicles,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[os, strutils, sequtils, sysrand, math],
std/[options, os, strutils, sequtils, sysrand, math],
stew/byteutils,
testutils/unittests,
chronos,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/sequtils,
std/[options, sequtils],
testutils/unittests,
chronicles,
chronos,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/net,
std/[options, net],
testutils/unittests,
chronos,
libp2p/crypto/crypto,

View 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