From d7c0486968d7a3dce31373fda7687881a722d3d8 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 15 May 2024 16:14:37 +0200 Subject: [PATCH] add withvalue for result --- libp2p/utility.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libp2p/utility.nim b/libp2p/utility.nim index 211ddbec4..2fa236c4c 100644 --- a/libp2p/utility.nim +++ b/libp2p/utility.nim @@ -112,6 +112,9 @@ template withValue*[T](self: Opt[T] | Option[T], value, body: untyped): untyped let value {.inject.} = temp.get() body +template withValue*[T, E](self: Result[T, E], value, body: untyped): untyped = + self.toOpt().withValue(value, body) + macro withValue*[T](self: Opt[T] | Option[T], value, body, elseStmt: untyped): untyped = let elseBody = elseStmt[0] quote do: