logos.lang.result

Module lang · package logos-lang

Types

enumResult

enum Result

Represents either success (Ok(T)) or failure (Err(E)).

The ? operator propagates Err early from functions returning Result<_, E>.

Implements: Eq IntoIterator FromIterator Debug

Variants

Err(E)
Ok(T)

Methods

fn and(self: Result, res: Result) -> Result

Returns res if the result is Ok, otherwise the Err value of self.

res is eagerly evaluated; use and_then for a lazily computed continuation.

fn and_then(self: Result, f: fn(T) -> Result) -> Result

Calls f with the contained Ok value, otherwise propagates the Err.

fn as_mut(self: &mut Result) -> Result

Converts from &mut Result<T, E> to Result<&mut T, &mut E>.

fn as_ref(self: &Result) -> Result

Converts from &Result<T, E> to Result<&T, &E>, borrowing the contained value.

fn err(self: Result) -> Option

Converts to Option<E>: Err(e) becomes Some(e), discarding the success value.

fn expect(self: Result, msg: &[u8]) -> T

Returns the contained Ok value; panics with msg if the result is Err.

fn expect_err(self: Result, msg: &[u8]) -> E

Returns the contained Err value; panics with msg if the result is Ok.

fn flatten(self: Result) -> Result

Removes one level of nesting: Ok(inner) yields inner, Err(e) stays Err(e).

fn is_err(self: &Result) -> bool

Returns true if the result is Err.

fn is_err_and(self: Result, pred: fn(E) -> bool) -> bool

Returns true if the result is Err and pred returns true for the contained error.

Consumes self (the error is passed to pred by value).

fn is_ok(self: &Result) -> bool

Returns true if the result is Ok.

fn is_ok_and(self: Result, pred: fn(T) -> bool) -> bool

Returns true if the result is Ok and pred returns true for the contained value.

Consumes self (the value is passed to pred by value).

fn map(self: Result, f: fn(T) -> U) -> Result

Applies f to a contained Ok value, leaving an Err value untouched.

fn map_err(self: Result, f: fn(E) -> F) -> Result

Applies f to a contained Err value, leaving an Ok value untouched.

fn map_or(self: Result, default: U, f: fn(T) -> U) -> U

Returns default if Err, or applies f to the contained Ok value.

fn map_or_else(self: Result, dfl: fn(E) -> U, f: fn(T) -> U) -> U

Maps to U by applying f to a contained Ok value, or dfl to a contained Err.

fn ok(self: Result) -> Option

Converts to Option<T>: Ok(v) becomes Some(v), discarding the error.

fn or(self: Result, res: Result) -> Result

Returns res if the result is Err, otherwise the Ok value of self.

res is eagerly evaluated; use or_else for a lazily computed fallback.

fn or_else(self: Result, f: fn(E) -> Result) -> Result

Calls f with the contained Err value, otherwise propagates the Ok.

fn transpose(self: Result) -> Option

Transposes a Result of an Option into an Option of a Result.

Ok(None)None; Ok(Some(v))Some(Ok(v)); Err(e)Some(Err(e)).

fn unwrap(self: Result) -> T

Returns the contained Ok value; panics if the result is Err.

The panic message is fixed — the error value is not formatted into it.

fn unwrap_err(self: Result) -> E

Returns the contained Err value; panics if the result is Ok.

fn unwrap_or(self: Result, default: T) -> T

Returns the contained Ok value or default.

default is eagerly evaluated; use unwrap_or_else for a lazily computed fallback.

fn unwrap_or_else(self: Result, f: fn(E) -> T) -> T

Returns the contained Ok value or computes a fallback from the error with f.

Functions

fnis_err_i32

fn is_err_i32(r: Result) -> bool

Returns true if r is Err; i32-monomorphic shim for is_err.

fnis_ok_i32

fn is_ok_i32(r: Result) -> bool

Returns true if r is Ok; i32-monomorphic shim for is_ok.

fnresult_flatten

fn result_flatten(r: Result) -> Result

Removes one level of Result nesting; free-fn form of flatten.

fnresult_transpose

fn result_transpose(r: Result) -> Option

Transposes a Result of an Option into an Option of a Result; free-fn form of transpose.

Ok(None)None; Ok(Some(v))Some(Ok(v)); Err(e)Some(Err(e)).

fnresult_unwrap_or_default

fn result_unwrap_or_default(r: Result) -> T

Returns the contained Ok value, or T::default() if Err.

Free-fn form of Rust’s Result::unwrap_or_default.

fnunwrap_or_i32

fn unwrap_or_i32(r: Result, def: i32) -> i32

Returns the contained Ok value or def; i32-monomorphic shim for unwrap_or.