Skip to main content

CorrelationContext

Struct CorrelationContext 

Source
pub struct CorrelationContext { /* private fields */ }
Expand description

Per-request correlation context. Cheaply clonable via Arc. Shares the underlying request state; mutating one clone is visible to the others.

Implementations§

Source§

impl CorrelationContext

Source

pub fn new() -> Self

Creates a context with fresh random correlation and request IDs, Once flow, no user, and a default pagination limit of 15.

Source

pub fn with_ids(correlation_id: &str, request_id: &str) -> Self

Creates a context with the given correlation and request IDs. Other state matches CorrelationContext::new.

Source

pub fn is_multipart(&self) -> bool

Whether the request arrived as multipart/form-data.

Source

pub fn multipart(&self) -> Option<MultipartBody>

Decoded multipart payload, if the request was multipart.

Source

pub fn form_field(&self, name: &str) -> Option<String>

First value of a multipart text field, if the request was multipart.

Source

pub fn form_field_all(&self, name: &str) -> Vec<String>

All values of a repeated multipart text field.

Source

pub fn files(&self) -> Vec<UploadedFile>

Uploaded files in part order. Returns an empty vector when not multipart.

Source

pub fn files_for(&self, field: &str) -> Vec<UploadedFile>

Uploaded files for one form field.

Source

pub fn body_bytes(&self) -> Option<Vec<u8>>

Raw request body bytes, if any.

Source

pub fn body_string(&self) -> Result<String, ErrorResult>

Raw request body as a string. For multipart requests the body form field wins when present; otherwise the raw payload is decoded as UTF-8. Returns a 400 error when there is no request body, or it is not valid UTF-8. No validation is applied to unstructured payloads.

Source

pub fn body<T>(&self) -> Result<T, ErrorResult>

Deserializes and validates the request body as T.

Multipart requests decode the DTO from the body form field when present, otherwise from the merged text fields. Non-multipart bodies accept JSON with a form-urlencoded fallback. Returns a 400 error when the body is missing, cannot be deserialized, or fails Validate.

let dto: MyDto = ctx.body::<MyDto>()?;
Source

pub fn headers(&self) -> HeaderMap

All request headers attached at dispatch.

Source

pub fn header(&self, name: &str) -> Option<String>

A single request header value, if present.

Source

pub fn query_params(&self) -> HashMap<String, String>

All query parameters attached at dispatch.

Source

pub fn query_param(&self, name: &str) -> Option<String>

A single query parameter value, if present.

Source

pub fn query_param_or(&self, name: &str, default: &str) -> String

A query parameter value, or default when absent.

Source

pub fn correlation_id(&self) -> String

Returns the correlation ID shared across related requests.

Source

pub fn request_id(&self) -> String

Returns the ID unique to this request.

Source

pub fn set_request_id(&self, id: &str)

Replaces the request ID.

Source

pub fn set_correlation_id(&self, id: &str)

Replaces the correlation ID.

Source

pub fn flow(&self) -> CorrelationFlow

Returns the current lifecycle flow marker.

Source

pub fn set_flow(&self, flow: CorrelationFlow)

Replaces the lifecycle flow marker.

Source

pub fn with_flow(self, flow: CorrelationFlow) -> Self

Sets the lifecycle flow marker and returns the context for chaining.

Source

pub fn with_correlation_id(self, id: &str) -> Self

Sets the correlation ID and returns the context for chaining.

Source

pub fn user_id(&self) -> Option<String>

Returns the authenticated user ID, if one was attached.

Source

pub fn set_user_id(&self, id: Option<String>)

Sets or clears the authenticated user ID.

Source

pub fn set(&self, key: &str, value: String)

Stores an arbitrary string value under key.

Source

pub fn get(&self, key: &str) -> Option<String>

Returns the arbitrary string value stored under key, if any.

Source

pub fn pagination_cursor(&self) -> Option<String>

Returns the pagination cursor, if one was attached.

Source

pub fn pagination_limit(&self) -> usize

Returns the pagination limit (defaults to 15).

Source

pub fn set_pagination(&self, cursor: Option<String>, limit: usize)

Sets the pagination cursor and limit.

Source

pub fn client_ip(headers: &HeaderMap, remote_addr: Option<SocketAddr>) -> String

Extracts the client IP, preferring x-forwarded-for (first entry), then x-real-ip, then the socket address, else "unknown".

Trait Implementations§

Source§

impl Clone for CorrelationContext

Source§

fn clone(&self) -> CorrelationContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CorrelationContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CorrelationContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more