Skip to content

Result

1 min read

No import is needed.

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

Result

Result<T, E> - the outcome of an operation that may fail.

public enum Result<T, E>

Ok

Contains the successful result.

Ok(T)

Err

Contains the error result.

Err(E)

is_ok

True when this is Ok.

public fun is_ok(): bool

is_err

True when this is Err.

public fun is_err(): bool

unwrap_or

The success value when Ok, otherwise fallback.

public fun unwrap_or(fallback: T): T

unwrap

The success value, or panics if Err.

public fun unwrap(): T

expect

The success value, or panics with msg if Err.

public fun expect(borrow msg: string): T

unwrap_or_else

The success value, or f(error) when Err.

public fun unwrap_or_else(borrow f: fun(E): T): T

unwrap_err

The error value, or panics if Ok.

public fun unwrap_err(): E

ok

Some when Ok, otherwise None.

public fun ok(): Option<T>

or_else

Maps Err through f, otherwise preserves Ok.

public fun or_else<F>(borrow f: fun(E): Result<T, F>): Result<T, F>

map

Maps the success value when Ok, otherwise preserves the error.

public fun map<U>(borrow f: fun(T): U): Result<U, E>

map_err

Maps the error when Err, otherwise preserves the success value.

public fun map_err<F>(borrow f: fun(E): F): Result<T, F>

and_then

Chains into another Result when Ok, otherwise preserves the error.

public fun and_then<U>(borrow f: fun(T): Result<U, E>): Result<U, E>