Skip to main content

WithRequestContext

Trait WithRequestContext 

Source
pub trait WithRequestContext {
    // Required method
    fn with_request_context(self, uri: &Uri) -> Self;
}
Expand description

Middleware-friendly: enrich errors from Axum extractors

Use this in handlers to automatically add trace context:

async fn handler(uri: Uri) -> Result<Json<Data>, Problem> {
    let data = fetch_data()
        .await
        .map_err(Problem::from)
        .map_err(|p| p.with_request_context(&uri))?;
    Ok(Json(data))
}

Required Methods§

Source

fn with_request_context(self, uri: &Uri) -> Self

Add trace_id and instance from the current request

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§