Module std::result

Result<T, E>'s methods. Result is the prelude's enum; its inherent methods are this module's, which every program loads, so r.is_ok() needs no use. Only unwrap and expect can panic: their rows ask for Panic. The combinators take closures as std::iter's adapters do (F: Fn(T) -> U, std::fun), whose bodies run with no capabilities, so their rows are empty. std::string prints a result as it is written, Ok(3) or Err(e).

Source: std/result.weir; committed interface: std/result.iface. Index

fn catch

pub fn catch<T: linear, E: owned>(f: fn() -> T with Throw<E> portable) -> Result<T, E>

Runs f, answering Ok with its result, or Err(e) if it throws e.

The Throw<E> that e? and throw(e) in f use is served here, so catch(|| parse(s)) is a Result again. The error borrows nothing (E: owned).

Committed interface (std/result.iface):

callback f: envelope {A, S}

impl<T: linear, E: linear> Result<T, E>

method is_ok

pub fn is_ok(&self) -> Bool

Whether it is Ok.

method is_err

pub fn is_err(&self) -> Bool

Whether it is Err.

method as_ref

pub fn as_ref(&self) -> Result<&T, &E>

A borrow of the value or of the error.

impl<T, E> Result<T, E>

method ok

pub fn ok(self) -> Option<T>

The value, if there is one; the error is dropped.

method err

pub fn err(self) -> Option<E>

The error, if there is one; the value is dropped.

method unwrap_or

pub fn unwrap_or(self, d: T) -> T

The value, else d; the error is dropped.

method unwrap_or_else

pub fn unwrap_or_else<F: Fn(E) -> T>(self, f: F) -> T

The value, else what f makes of the error; f runs only on Err.

method map

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> Result<U, E>

Ok(f(x)) of the value x; an error is passed on unchanged.

method map_err

pub fn map_err<G, F: Fn(E) -> G>(self, f: F) -> Result<T, G>

Err(f(e)) of the error e; a value is passed on unchanged.

method and_then

pub fn and_then<U, F: Fn(T) -> Result<U, E>>(self, f: F) -> Result<U, E>

f(x) of the value x, which may itself fail; an error is passed on unchanged.

method or_else

pub fn or_else<G, F: Fn(E) -> Result<T, G>>(self, f: F) -> Result<T, G>

f(e) of the error e, which may recover; a value is passed on unchanged.

method is_ok_and

pub fn is_ok_and<P: Fn(T) -> Bool>(self, p: P) -> Bool

Whether it is Ok and p holds of the value; p takes the value, an error is dropped.

method is_err_and

pub fn is_err_and<P: Fn(E) -> Bool>(self, p: P) -> Bool

Whether it is Err and p holds of the error; p takes the error, a value is dropped.

method unwrap

pub fn unwrap(self) -> T with Panic {panic: raise} migrates cross

The value; an Err panics (raise) with a fixed message, the error dropped unshown.

method expect

pub fn expect(self, m: Str) -> T with Panic {panic: raise} migrates cross

The value; an Err panics with the message m, the error dropped.