pub struct ApiResultLayer { /* private fields */ }Expand description
Actix-web middleware layer that auto-injects trace_id (and optionally timestamp)
into ApiResult responses.
§How it works
- Extracts a trace ID from request headers (or generates a UUID v4)
- Stores it in request extensions as
ApiTraceId - The
Responderimpl forApiResult<T>reads the extension and injects it
This approach is zero-overhead: no body re-serialization needed.
§Usage
ⓘ
use actix_web::App;
use anycms_core::actix::ApiResultLayer;
App::new()
.wrap(ApiResultLayer::default())
.route("/users", web::get().to(list_users))Implementations§
Source§impl ApiResultLayer
impl ApiResultLayer
Sourcepub fn new(config: ApiResultMiddlewareConfig) -> Self
pub fn new(config: ApiResultMiddlewareConfig) -> Self
Create a new layer with the given configuration.
Trait Implementations§
Source§impl Default for ApiResultLayer
Available on crate feature actix only.
impl Default for ApiResultLayer
Available on crate feature
actix only.Source§impl<S, B> Transform<S, ServiceRequest> for ApiResultLayerwhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
Available on crate feature actix only.
impl<S, B> Transform<S, ServiceRequest> for ApiResultLayerwhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
Available on crate feature
actix only.Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
Source§type Transform = ApiResultMiddleware<S>
type Transform = ApiResultMiddleware<S>
The
TransformService value created by this factorySource§type Future = Ready<Result<<ApiResultLayer as Transform<S, ServiceRequest>>::Transform, <ApiResultLayer as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<ApiResultLayer as Transform<S, ServiceRequest>>::Transform, <ApiResultLayer as Transform<S, ServiceRequest>>::InitError>>
The future response value.
Source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations§
impl Freeze for ApiResultLayer
impl RefUnwindSafe for ApiResultLayer
impl Send for ApiResultLayer
impl Sync for ApiResultLayer
impl Unpin for ApiResultLayer
impl UnsafeUnpin for ApiResultLayer
impl UnwindSafe for ApiResultLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more