Type Alias error_stack::Result

source ·
pub type Result<T, C> = Result<T, Report<C>>;
Expand description

Result<T, Report<C>>

A reasonable return type to use throughout an application.

The Result type can be used with one or two parameters, where the first parameter represents the Ok arm and the second parameter Context is used as in Report<C>.

§Examples

Result can also be used in fn main():

use error_stack::{ensure, Result};

fn main() -> Result<(), AccessError> {
    let user = get_user()?;
    let resource = get_resource()?;

    ensure!(
        has_permission(user, resource),
        AccessError::PermissionDenied(user, resource)
    );

    ...
}

Aliased Type§

enum Result<T, C> {
    Ok(T),
    Err(Report<C>),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(Report<C>)

Contains the error value

Trait Implementations§

source§

impl<T, C> ResultExt for Result<T, C>
where C: Context,

§

type Context = C

The Context type of the Result.
§

type Ok = T

Type of the Ok value in the Result
source§

fn attach<A>(self, attachment: A) -> Self
where A: Send + Sync + 'static,

Adds a new attachment to the Report inside the Result. Read more
source§

fn attach_lazy<A, F>(self, attachment: F) -> Self
where A: Send + Sync + 'static, F: FnOnce() -> A,

Lazily adds a new attachment to the Report inside the Result. Read more
source§

fn attach_printable<A>(self, attachment: A) -> Self
where A: Display + Debug + Send + Sync + 'static,

Adds a new printable attachment to the Report inside the Result. Read more
source§

fn attach_printable_lazy<A, F>(self, attachment: F) -> Self
where A: Display + Debug + Send + Sync + 'static, F: FnOnce() -> A,

Lazily adds a new printable attachment to the Report inside the Result. Read more
source§

fn change_context<C2>(self, context: C2) -> Result<T, C2>
where C2: Context,

Changes the context of the Report inside the Result. Read more
source§

fn change_context_lazy<C2, F>(self, context: F) -> Result<T, C2>
where C2: Context, F: FnOnce() -> C2,

Lazily changes the context of the Report inside the Result. Read more