From a7a7e99a2e6b709bd5f5739610058800ffbf2d13 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Wed, 26 Jul 2023 16:53:25 -0700 Subject: [PATCH] add inline ?! type and documentation tweaks --- questionable/results.nim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/questionable/results.nim b/questionable/results.nim index 5d61945..9cdd1df 100644 --- a/questionable/results.nim +++ b/questionable/results.nim @@ -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.