results: make `?` work with void (#50)
This commit is contained in:
parent
61e0f82858
commit
ec2f52b0ce
|
@ -621,7 +621,7 @@ template value*[E](self: var Result[void, E]) =
|
||||||
mixin get
|
mixin get
|
||||||
self.get()
|
self.get()
|
||||||
|
|
||||||
template `?`*[T, E](self: Result[T, E]): T =
|
template `?`*[T, E](self: Result[T, E]): auto =
|
||||||
## Early return - if self is an error, we will return from the current
|
## Early return - if self is an error, we will return from the current
|
||||||
## function, else we'll move on..
|
## function, else we'll move on..
|
||||||
##
|
##
|
||||||
|
@ -639,4 +639,5 @@ template `?`*[T, E](self: Result[T, E]): T =
|
||||||
else:
|
else:
|
||||||
return err(typeof(result), v.e)
|
return err(typeof(result), v.e)
|
||||||
|
|
||||||
v.v
|
when not(T is void):
|
||||||
|
v.v
|
||||||
|
|
|
@ -256,3 +256,13 @@ except:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
doAssert vErr.mapErr(proc(x: int): int = 10).error() == 10
|
doAssert vErr.mapErr(proc(x: int): int = 10).error() == 10
|
||||||
|
|
||||||
|
func voidF(): VoidRes =
|
||||||
|
ok()
|
||||||
|
|
||||||
|
func voidF2(): VoidRes =
|
||||||
|
? voidF()
|
||||||
|
|
||||||
|
ok()
|
||||||
|
|
||||||
|
doAssert voidF2().isOk
|
||||||
|
|
Loading…
Reference in New Issue