mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-05 21:49:31 +00:00
* bump libp2p pin to release/v2.0.0 (c43199378) * pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt * add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix * migrate rng to libp2p Rng type (prod, channels, noise, tests) * noise: take Rng, extract bearSslDrbg internally * waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery) * tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng() * drop libp2p/utils/semaphore (use chronos AsyncSemaphore) * add waku/compat/option_valueor shim where needed * add std/options where transitive re-export dropped
36 lines
1.0 KiB
Nim
36 lines
1.0 KiB
Nim
## Polyfill: `valueOr` / `withValue` templates for `std/options.Option[T]`.
|
|
##
|
|
## Previously provided transitively by `libp2p/utility`, removed in
|
|
## nim-libp2p PR #2162 (commit 8a9943145). logos-delivery uses these
|
|
## templates pervasively on `Option[T]`. The shim restores them here while
|
|
## we adapt to upstream churn; collocated under `waku/compat/` so the
|
|
## category is explicit (compatibility with upstream API drift), not a
|
|
## generic dumping ground.
|
|
|
|
{.push raises: [].}
|
|
|
|
import std/[macros, options]
|
|
|
|
template valueOr*[T](self: Option[T], body: untyped): untyped =
|
|
let temp = (self)
|
|
if temp.isSome:
|
|
temp.get()
|
|
else:
|
|
body
|
|
|
|
template withValue*[T](self: Option[T], value, body: untyped): untyped =
|
|
let temp = (self)
|
|
if temp.isSome:
|
|
let `value` {.inject.} = temp.get()
|
|
body
|
|
|
|
macro withValue*[T](self: Option[T], value, body, elseStmt: untyped): untyped =
|
|
let elseBody = elseStmt[0]
|
|
quote:
|
|
let temp = (`self`)
|
|
if temp.isSome:
|
|
let `value` {.inject.} = temp.get()
|
|
`body`
|
|
else:
|
|
`elseBody`
|