Skip to content

Commit

Permalink
results: work around nim codegen bug
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jun 8, 2023
1 parent 13e55ed commit 469ec2f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stew/results.nim
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,12 @@ template tryGet*[E](self: Result[void, E]) = self.tryValue()
template unsafeGet*[T: not void, E](self: Result[T, E]): T = self.unsafeValue()
template unsafeGet*[E](self: Result[void, E]) = self.unsafeValue()

# `var` overloads should not be needed but result in invalid codegen (!):
# TODO https://github.com/nim-lang/Nim/issues/22049
template get*[T: not void, E](self: var Result[T, E]): var T = self.value()
template tryGet*[T: not void, E](self: var Result[T, E]): var T = self.tryValue()
template unsafeGet*[T: not void, E](self: var Result[T, E]): var T = self.unsafeValue()

func get*[T, E](self: Result[T, E], otherwise: T): T {.inline.} =
## Fetch value of result if set, or return the value `otherwise`
## See `valueOr` for a template version that avoids evaluating `otherwise`
Expand Down

0 comments on commit 469ec2f

Please sign in to comment.