add inline ?! type and documentation tweaks

This commit is contained in:
Jaremy Creechley 2023-07-26 16:53:25 -07:00
parent b3cf35ac45
commit a7a7e99a2e
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -20,12 +20,22 @@ export withoutresult
type ResultFailure* = object of CatchableError
template `?!`*(T: typed): type Result[T, ref CatchableError] =
## Use `?!` make a Result type. These Result types either hold a value or
## an error. For example the type `?!int` is short for
## `Result[int, ref CatchableError]`.
## Use `?!` to declare a Result type for `T` with an error of `ref CatchableError`.
##
## Result types either hold a value or an error. For example
## the type `?!int` is short for `Result[int, ref CatchableError]`.
##
Result[T, ref CatchableError]
template `?!`*[T; E: CatchableError](t: typedesc[T], e: typedesc[E]): type Result[T, ref E] =
## Use inline `?!` to declare a Result type for `T` with a given error type.
##
## Result types either hold a value or an error. For example
## the type `string ?! KeyError` is short for `Result[string, ref KeyError]`.
##
Result[T, ref E]
template `!`*[T](value: ?!T): T =
## Returns the value of a Result when you're absolutely sure that it
## contains value. Using `!` on a Result without a value raises a Defect.