Expand description
Async prelude - all async utilities in one import (requires async feature)
Async prelude - all async utilities in one import.
This module provides all the async-related items needed for async error handling.
It re-exports everything from the sync prelude plus async-specific items.
§Usage
use error_rail::prelude_async::*;
#[derive(Debug)]
struct User;
#[derive(Debug)]
struct ApiError;
async fn fetch_from_db(_id: u64) -> Result<User, ApiError> {
Err(ApiError)
}
async fn fetch_user(id: u64) -> BoxedResult<User, ApiError> {
fetch_from_db(id)
.ctx("fetching user from database")
.await
.map_err(Box::new)
}§What’s Included
§From Sync Prelude
- Macros:
context!,group!,rail!,rail_unboxed! - Types:
ComposableError,ErrorContext,ErrorPipeline - Traits:
ResultExt,BoxedResultExt,IntoErrorContext - Type Alias:
BoxedResult
§Async-Specific
- Traits:
FutureResultExt-.ctx()and.with_ctx()for futures - Types:
AsyncErrorPipeline,ContextFuture - Macros:
rail_async!,ctx_async!
§Async Retry (requires async feature)
- Traits:
RetryPolicy - Types:
ExponentialBackoff,FixedDelay - Functions:
retry_with_policy
§Async Validation (requires async feature)
- Functions:
validate_all_async,validate_seq_async
§Tokio Integration (requires ecosystem feature)
- Functions:
retry_transient,retry_transient_n,try_with_timeout - Types:
TimeoutResult,TimeoutError
§Tracing Integration (requires tracing feature)
- Traits:
FutureSpanExt,ResultSpanExt - Functions:
instrument_error
Re-exports§
pub use crate::async_ext::AsyncErrorPipeline;pub use crate::async_ext::ContextFuture;pub use crate::async_ext::FutureResultExt;pub use crate::async_ext::retry_with_metadata;pub use crate::async_ext::retry_with_policy;pub use crate::async_ext::ExponentialBackoff;pub use crate::async_ext::FixedDelay;pub use crate::async_ext::RetryPolicy;pub use crate::async_ext::RetryResult;pub use crate::async_ext::validate_all_async;pub use crate::async_ext::validate_seq_async;pub use crate::async_ext::retry_transient;pub use crate::async_ext::retry_transient_n;pub use crate::async_ext::retry_transient_unboxed;pub use crate::async_ext::try_with_timeout;pub use crate::async_ext::TimeoutError;pub use crate::async_ext::TimeoutResult;pub use crate::async_ext::instrument_error;pub use crate::async_ext::FutureSpanExt;pub use crate::async_ext::ResultSpanExt;pub use crate::async_ext::SpanContextFuture;pub use crate::prelude::*;
Macros§
- ctx_
async - Attaches context to a future’s error with format string support.
- rail_
async - Wraps a future in an
AsyncErrorPipeline.