mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-09 11:45:42 +00:00
parent
b4b3841a85
commit
6d3e6a21ca
@ -442,7 +442,7 @@ template capture*[E: Exception](T: type, someExceptionExpr: ref E): Result[T, re
|
|||||||
ret = R.err(caught)
|
ret = R.err(caught)
|
||||||
ret
|
ret
|
||||||
|
|
||||||
func `==`*[T0, E0, T1, E1](lhs: Result[T0, E0], rhs: Result[T1, E1]): bool {.inline.} =
|
func `==`*[T0: not void, E0, T1: not void, E1](lhs: Result[T0, E0], rhs: Result[T1, E1]): bool {.inline.} =
|
||||||
if lhs.o != rhs.o:
|
if lhs.o != rhs.o:
|
||||||
false
|
false
|
||||||
elif lhs.o: # and rhs.o implied
|
elif lhs.o: # and rhs.o implied
|
||||||
@ -450,6 +450,12 @@ func `==`*[T0, E0, T1, E1](lhs: Result[T0, E0], rhs: Result[T1, E1]): bool {.inl
|
|||||||
else:
|
else:
|
||||||
lhs.e == rhs.e
|
lhs.e == rhs.e
|
||||||
|
|
||||||
|
func `==`*[E0, E1](lhs: Result[void, E0], rhs: Result[void, E1]): bool {.inline.} =
|
||||||
|
if lhs.o != rhs.o:
|
||||||
|
false
|
||||||
|
else:
|
||||||
|
lhs.e == rhs.e
|
||||||
|
|
||||||
func get*[T: not void, E](self: Result[T, E]): T {.inline.} =
|
func get*[T: not void, E](self: Result[T, E]): T {.inline.} =
|
||||||
## Fetch value of result if set, or raise Defect
|
## Fetch value of result if set, or raise Defect
|
||||||
## Exception bridge mode: raise given Exception instead
|
## Exception bridge mode: raise given Exception instead
|
||||||
|
@ -275,3 +275,8 @@ func cstringF(s: string): CSRes =
|
|||||||
doAssert false
|
doAssert false
|
||||||
|
|
||||||
discard cstringF("test")
|
discard cstringF("test")
|
||||||
|
|
||||||
|
# Compare void
|
||||||
|
block:
|
||||||
|
var a, b: Result[void, bool]
|
||||||
|
discard a == b
|
||||||
|
Loading…
x
Reference in New Issue
Block a user