Result

enum Result<Success, Failure>

A recoverable computation that contains either a success or a failure value.

Use Result when failure is ordinary data that the caller should inspect; use an effect for dynamically handled control flow, or Optional when only presence matters. Exactly one payload is initialized and owned at a time.

Cases

case ok(Success)

Contains the operation's successful value.

case error(Failure)

Contains the recoverable failure value.

Methods

func is_ok() -> Bool

Returns true only for ok results.

View Source
pub func is_ok() -> Bool {
	match self {
		.ok(_) -> true,
		.error(_) -> false
	}
}

func is_error() -> Bool

Returns true only for error results.

View Source
pub func is_error() -> Bool {
	match self {
		.ok(_) -> false,
		.error(_) -> true
	}
}

consuming func map<T>(ok: (consume Success) -> T) -> Result<T, Failure>

Consumes and transforms an ok payload while forwarding error unchanged.

The callback is never invoked for a failure.

View Source
pub consuming func map<T>(ok: (consume Success) -> T) -> Result<T, Failure> {
	match self {
		.ok(val) -> .ok(ok(val)),
		.error(e) -> .error(e)
	}
}

consuming func map<T>(err: (consume Failure) -> T) -> Result<Success, T>

Consumes and transforms an error payload while forwarding ok unchanged.

The callback is never invoked for a success.

View Source
pub consuming func map<T>(err: (consume Failure) -> T) -> Result<Success, T> {
	match self {
		.ok(ok) -> .ok(ok),
		.error(e) -> .error(err(e))
	}
}