Trait celery::task::TaskResultExt
source · 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§
sourcefn with_expected_err(self, f: F) -> Result<T, TaskError>
fn with_expected_err(self, f: F) -> Result<T, TaskError>
Convert the error type to a TaskError::ExpectedError
.
sourcefn with_unexpected_err(self, f: F) -> Result<T, TaskError>
fn with_unexpected_err(self, f: F) -> Result<T, TaskError>
Convert the error type to a TaskError::UnexpectedError
.