Calling success without arguments returns ?!void result

This commit is contained in:
Mark Spanbroek 2021-04-15 11:04:26 +02:00
parent a66e42d058
commit 144c70580a
2 changed files with 6 additions and 0 deletions

View File

@ -15,6 +15,9 @@ template `?!`*(T: typed): type Result[T, ref CatchableError] =
proc success*[T](value: T): ?!T =
ok(?!T, value)
proc success*: ?!void =
ok(?!void)
proc failure*(T: type, error: ref CatchableError): ?!T =
err(?!T, error)

View File

@ -112,6 +112,9 @@ suite "result":
check parseInt("42").catch == 42.success
check parseInt("foo").catch.error of ValueError
test "success can be called without argument":
check (success() is ?!void)
test "failure can be called with string argument":
let value = int.failure("some failure")
check value.error of ResultFailure