error_rail/async_ext/
mod.rs

1//! Async extensions for error-rail.
2//!
3//! This module provides async-aware error handling utilities that maintain
4//! the same lazy attachment philosophy as the sync counterparts.
5//!
6//! Note: lazy *string formatting* is provided by `context!` / `.with_ctx(...)`.
7//! Passing an already-formatted `String` (e.g. `format!(...)`) is eager.
8//!
9//! # Feature Flag
10//!
11//! Requires the `async` feature to be enabled:
12//!
13//! ```toml
14//! [dependencies]
15//! error-rail = { version = "0.8", features = ["async"] }
16//! ```
17//!
18//! # Examples
19//!
20//! ```rust,no_run
21//! use error_rail::prelude_async::*;
22//!
23//! #[derive(Debug)]
24//! struct User;
25//!
26//! #[derive(Debug)]
27//! struct ApiError;
28//!
29//! async fn fetch_from_db(_id: u64) -> Result<User, ApiError> {
30//!     Err(ApiError)
31//! }
32//!
33//! async fn fetch_user(id: u64) -> BoxedResult<User, ApiError> {
34//!     fetch_from_db(id)
35//!         .ctx("fetching user from database")
36//!         .await
37//!         .map_err(Box::new)
38//! }
39//! ```
40
41mod context_future;
42mod future_ext;
43mod pipeline;
44
45#[cfg(feature = "async")]
46mod retry;
47
48#[cfg(feature = "async")]
49mod validation;
50
51#[cfg(feature = "tokio")]
52mod tokio_ext;
53
54#[cfg(feature = "tracing")]
55mod tracing_ext;
56
57pub use context_future::ContextFuture;
58pub use future_ext::FutureResultExt;
59pub use pipeline::AsyncErrorPipeline;
60
61#[cfg(feature = "async")]
62pub use retry::{
63    retry_with_metadata, retry_with_policy, ExponentialBackoff, FixedDelay, RetryPolicy,
64    RetryResult,
65};
66
67#[cfg(feature = "async")]
68pub use validation::{validate_all_async, validate_seq_async};
69
70#[cfg(feature = "tokio")]
71pub use tokio_ext::{
72    retry_transient, retry_transient_n, retry_transient_unboxed, try_with_timeout, TimeoutError,
73    TimeoutResult,
74};
75
76#[cfg(feature = "tracing")]
77pub use tracing_ext::{instrument_error, FutureSpanExt, ResultSpanExt, SpanContextFuture};