results.`==` with void, Reboot #73 addressing comments (#74)

This commit is contained in:
Mamy Ratsimbazafy 2021-01-26 15:06:17 +01:00 committed by GitHub
parent b4b3841a85
commit 6d3e6a21ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -442,7 +442,7 @@ template capture*[E: Exception](T: type, someExceptionExpr: ref E): Result[T, re
ret = R.err(caught)
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:
false
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:
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.} =
## Fetch value of result if set, or raise Defect
## Exception bridge mode: raise given Exception instead

View File

@ -275,3 +275,8 @@ func cstringF(s: string): CSRes =
doAssert false
discard cstringF("test")
# Compare void
block:
var a, b: Result[void, bool]
discard a == b