pub trait TaskResultExt<T, E, F, C> {
    // Required methods
    fn with_expected_err(self, f: F) -> Result<T, TaskError>;
    fn with_unexpected_err(self, f: F) -> Result<T, TaskError>;
}
Expand description

Extension methods for Result types within a task body.

These methods can be used to convert a Result<T, E> to a Result<T, TaskError> with the appropriate TaskError variant. The trait has a blanket implementation for any error type that implements std::error::Error.

Examples

fn do_some_io() -> Result<(), std::io::Error> {
    unimplemented!()
}

#[celery::task]
fn fallible_io_task() -> TaskResult<()> {
    do_some_io().with_expected_err(|| "IO error")?;
    Ok(())
}

Required Methods§

source

fn with_expected_err(self, f: F) -> Result<T, TaskError>

Convert the error type to a TaskError::ExpectedError.

source

fn with_unexpected_err(self, f: F) -> Result<T, TaskError>

Convert the error type to a TaskError::UnexpectedError.

Implementations on Foreign Types§

source§

impl<T, E, F, C> TaskResultExt<T, E, F, C> for Result<T, E>where E: Error, F: FnOnce() -> C, C: Display + Send + Sync + 'static,

Implementors§