diff --git a/doc/op.html b/doc/op.html index 4007e72..435c53d 100644 --- a/doc/op.html +++ b/doc/op.html @@ -101,34 +101,44 @@ function main() {
OP[T] = object - case isOk*: bool + +
Either[A; B] = object + case isA*: bool of true: - val*: T + a*: A of false: - error*: string + b*: B
Object to wrap the result of an operation.
+An Either object can hold either one value or the other, but never both + +OP[T] = Either[T, string]
Object to wrap the result of an operation. Alias of Either with a string as error message
The type is discriminated by the isOK bool. So it is an compiler error to try to access the value without checking if the operation was successful.
proc ok[T](val: T): OP[T] {...}{.inline.}
template checkA(self: Either): bool
template getA[A; B](self: Either[A, B]): A
template getB[A; B](self: Either[A, B]): B
template isOK(self: OP): bool
template val(self: OP): auto
template error(self: OP): auto
template ok[T](val: T): OP[T]
proc fail(op: OP; msg: string): OP {...}{.inline.}
template ok[T](self: var OP[T]; val: T)
Examples:
-proc someProc(): OP[int] = - result.fail "Not implemented!" - -let data = someProc() -assert data.isOk == false -assert data.error == "Not implemented!"+Set the result to the given value
proc fail(T: typedesc; msg: string): OP[T] {...}{.inline.}
template fail[T; ](O: type OP[T]; msg: string): O:type
Will create a new operation result with the given error message. The type for the operation result is given explicitly.
@@ -219,17 +271,31 @@ Will create a new operation result with the given error message. The type for thtemplate fail[T; ](O: type OP[T]; msg: string): O:type
template fail(T: typedesc; msg: string): OP[T]
Will create a new operation result with the given error message. The type for the operation result is given explicitly.
+See Also:
+ +template fail(op: OP; msg: string): OP
Examples:
+proc someProc(): OP[int] = + result.fail "Not implemented!" + +let data = someProc() +assert data.isOk == false +assert data.error == "Not implemented!"+
template fail(msg: static[string]): auto