badresults

Source   Edit  

Types

Result[T; E] = object
  case
  of false:
  of true:
For documentation, refer to the original nim-results package, or this source code. I'm deleting the original documentation from here as it's either annoying or incorrect. Source   Edit  
ResultError[E] = ref object of ValueError
Source   Edit  

Procs

func `$`[E](self: Result[void, E]): string
Returns string representation of self Source   Edit  
proc `$`[T: not void; E](self: Result[T, E]): string
Returns string representation of self Source   Edit  
func `==`(a, b: Result): bool {.inline.}
Source   Edit  
proc err[T, E](R: typedesc[Result[T, E]]; e: E): Result[T, E]
Return a result with an error. Example: Result[int, string].err("uh-oh") Source   Edit  
proc err[T, E](self: var Result[T, E]; e: E)
Set the result as an error. Example: result.err("uh-oh") Source   Edit  
proc error[T, E](self: Result[T, E]): E {.inline.}
Retrieve the error from a Result; raises ResultError if the Result is not in error. Source   Edit  
proc isErr(self: Result): bool
Source   Edit  
proc isOk(self: Result): bool
Source   Edit  
proc ok[E](R: typedesc[Result[void, E]]): Result[void, E]
Return a result as success. Source   Edit  
proc ok[E](self: var Result[void, E])
Set a result to success. Example: result.ok(42) Source   Edit  
proc ok[T, E](R: typedesc[Result[T, E]]; v: T): Result[T, E]
Return a result with a success and value. Example: Result[int, string].ok(42) Source   Edit  
proc ok[T, E](self: var Result[T, E]; v: T)
Set the result to success and update value. Example: result.ok(42) Source   Edit  
proc unsafeGet[E](self: Result[void, E]) {.inline.}
Raise an exception if Result is an error. See also: Option.unsafeGet Source   Edit  
proc unsafeGet[T, E](self: Result[T, E]): T {.inline.}
Fetch value of result if set, undefined behavior if unset See also: Option.unsafeGet Source   Edit  
proc unsafeGet[T, E](self: var Result[T, E]): var T {.inline.}
Fetch value of result if set, undefined behavior if unset See also: Option.unsafeGet Source   Edit  

Templates

template get[E](self: Result[void, E])
Raise error as an Exception if self.isErr. See also: Option.get Source   Edit  
template get[T, E](self: Result[T, E]; otherwise: T): untyped
Fetch value of result if set, or raise error as an Exception See also: Option.get Source   Edit  
template get[T, E](self: var Result[T, E]): untyped
Fetch mutable value of result if set, or raise error as an Exception See also: Option.get Source   Edit  
template get[T: not void; E](self: Result[T, E]): untyped
Fetch value of result if set, or raise error as an Exception See also: Option.get Source   Edit  
template toException[E](err: E): ResultError[E]
Source   Edit  
template value[E](self: Result[void, E])
Source   Edit  
template value[E](self: var Result[void, E])
Source   Edit  
template value[T, E](self: Result[T, E]): T
Source   Edit  
template value[T, E](self: var Result[T, E]): T
Source   Edit  
template valueOr[T, E](self: Result[T, E]; def: T): T
Fetch value of result if set, or supplied default default will not be evaluated iff value is set Source   Edit