Result v0.1.0
The return type of an operation that can fail.
Package: Rux
Definition
enum Result<T, E> {
Success(T),
Error(E)
}
A Result<T, E> holds either a Success carrying the value T an operation produced, or an Error carrying the failure E. Because the error is part of the return type, a caller cannot read the value without acknowledging that the call might have failed — the usual way is to match on the two variants.
import Core::Result;
match ParseInt64("42") {
.Success(n) => PrintLine(n),
.Error(e) => PrintLine("bad input")
}
Result is the recoverable-error half of Rux's error model; for conditions a caller is not expected to recover from, see Panic.
See also
Core— the package overview- The
ResultType — the language-reference treatment match— destructuringSuccessandErrorPanic— for unrecoverable errors