Some fixes for Result[T, void]

This commit is contained in:
Zahary Karadjov 2020-09-29 21:31:20 +03:00
parent 3e4dc8213b
commit 2b9e5f34d1
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 8 additions and 2 deletions

View File

@ -498,12 +498,18 @@ func expect*[T: not void, E](self: Result[T, E], m: string): T =
## echo r.expect("r was just set to ok(42)")
## ```
if not self.o:
when E isnot void:
raiseResultDefect(m, self.e)
else:
raiseResultDefect(m)
self.v
func expect*[T: not void, E](self: var Result[T, E], m: string): var T =
if not self.o:
when E isnot void:
raiseResultDefect(m, self.e)
else:
raiseResultDefect(m)
self.v
func `$`*(self: Result): string =