mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-02 22:03:10 +00:00
add inline ?! type and documentation tweaks
This commit is contained in:
parent
b3cf35ac45
commit
a7a7e99a2e
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user