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
impl CorrelationContext
Sourcepub fn new() -> Self
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.
Sourcepub fn with_ids(correlation_id: &str, request_id: &str) -> Self
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.
Sourcepub fn is_multipart(&self) -> bool
pub fn is_multipart(&self) -> bool
Whether the request arrived as multipart/form-data.
Sourcepub fn multipart(&self) -> Option<MultipartBody>
pub fn multipart(&self) -> Option<MultipartBody>
Decoded multipart payload, if the request was multipart.
Sourcepub fn form_field(&self, name: &str) -> Option<String>
pub fn form_field(&self, name: &str) -> Option<String>
First value of a multipart text field, if the request was multipart.
Sourcepub fn form_field_all(&self, name: &str) -> Vec<String>
pub fn form_field_all(&self, name: &str) -> Vec<String>
All values of a repeated multipart text field.
Sourcepub fn files(&self) -> Vec<UploadedFile>
pub fn files(&self) -> Vec<UploadedFile>
Uploaded files in part order. Returns an empty vector when not multipart.
Sourcepub fn files_for(&self, field: &str) -> Vec<UploadedFile>
pub fn files_for(&self, field: &str) -> Vec<UploadedFile>
Uploaded files for one form field.
Sourcepub fn body_bytes(&self) -> Option<Vec<u8>>
pub fn body_bytes(&self) -> Option<Vec<u8>>
Raw request body bytes, if any.
Sourcepub fn body_string(&self) -> Result<String, ErrorResult>
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.
Sourcepub fn body<T>(&self) -> Result<T, ErrorResult>where
T: DocumentableDTO + Validate,
pub fn body<T>(&self) -> Result<T, ErrorResult>where
T: DocumentableDTO + Validate,
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>()?;Sourcepub fn query_params(&self) -> HashMap<String, String>
pub fn query_params(&self) -> HashMap<String, String>
All query parameters attached at dispatch.
Sourcepub fn query_param(&self, name: &str) -> Option<String>
pub fn query_param(&self, name: &str) -> Option<String>
A single query parameter value, if present.
Sourcepub fn query_param_or(&self, name: &str, default: &str) -> String
pub fn query_param_or(&self, name: &str, default: &str) -> String
A query parameter value, or default when absent.
Sourcepub fn correlation_id(&self) -> String
pub fn correlation_id(&self) -> String
Returns the correlation ID shared across related requests.
Sourcepub fn request_id(&self) -> String
pub fn request_id(&self) -> String
Returns the ID unique to this request.
Sourcepub fn set_request_id(&self, id: &str)
pub fn set_request_id(&self, id: &str)
Replaces the request ID.
Sourcepub fn set_correlation_id(&self, id: &str)
pub fn set_correlation_id(&self, id: &str)
Replaces the correlation ID.
Sourcepub fn flow(&self) -> CorrelationFlow
pub fn flow(&self) -> CorrelationFlow
Returns the current lifecycle flow marker.
Sourcepub fn set_flow(&self, flow: CorrelationFlow)
pub fn set_flow(&self, flow: CorrelationFlow)
Replaces the lifecycle flow marker.
Sourcepub fn with_flow(self, flow: CorrelationFlow) -> Self
pub fn with_flow(self, flow: CorrelationFlow) -> Self
Sets the lifecycle flow marker and returns the context for chaining.
Sourcepub fn with_correlation_id(self, id: &str) -> Self
pub fn with_correlation_id(self, id: &str) -> Self
Sets the correlation ID and returns the context for chaining.
Sourcepub fn user_id(&self) -> Option<String>
pub fn user_id(&self) -> Option<String>
Returns the authenticated user ID, if one was attached.
Sourcepub fn set_user_id(&self, id: Option<String>)
pub fn set_user_id(&self, id: Option<String>)
Sets or clears the authenticated user ID.
Sourcepub fn get(&self, key: &str) -> Option<String>
pub fn get(&self, key: &str) -> Option<String>
Returns the arbitrary string value stored under key, if any.
Sourcepub fn pagination_cursor(&self) -> Option<String>
pub fn pagination_cursor(&self) -> Option<String>
Returns the pagination cursor, if one was attached.
Sourcepub fn pagination_limit(&self) -> usize
pub fn pagination_limit(&self) -> usize
Returns the pagination limit (defaults to 15).
Sourcepub fn set_pagination(&self, cursor: Option<String>, limit: usize)
pub fn set_pagination(&self, cursor: Option<String>, limit: usize)
Sets the pagination cursor and limit.
Trait Implementations§
Source§impl Clone for CorrelationContext
impl Clone for CorrelationContext
Source§fn clone(&self) -> CorrelationContext
fn clone(&self) -> CorrelationContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CorrelationContext
impl Debug for CorrelationContext
Auto Trait Implementations§
impl Freeze for CorrelationContext
impl RefUnwindSafe for CorrelationContext
impl Send for CorrelationContext
impl Sync for CorrelationContext
impl Unpin for CorrelationContext
impl UnsafeUnpin for CorrelationContext
impl UnwindSafe for CorrelationContext
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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