Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub request: Request,
    pub response: Response,
    pub route_params: RouteParams,
    pub attributes: ThreadSafeAttributeStore,
    /* private fields */
}
Expand description

Represents the internal state of the application context.

This structure holds all the data associated with a single request-response cycle, including the request, response, and any custom attributes.

Fields§

§request: Request

The incoming HTTP request.

§response: Response

The outgoing HTTP response.

§route_params: RouteParams

Parameters extracted from the route path.

§attributes: ThreadSafeAttributeStore

A collection of custom attributes for sharing data within the request lifecycle.

Implementations§

Source§

impl Context

Structured response serialization for Context.

Source

pub fn build_response(&mut self) -> ResponseData

Builds the response for the incoming request without sending it.

A wire HEAD request receives only the status line and headers, even if middleware rewrites the request method. A standalone context uses its current request method. Explicit raw stream writes are not affected.

§Returns
  • ResponseData - The serialized response bytes.
Source§

impl Context

Implementation of methods for Context structure.

Source

pub fn try_get_route_param<T>(&self, name: T) -> Option<String>
where T: AsRef<str>,

Attempts to retrieve a specific route parameter by its name.

§Arguments
  • T - The name of the route parameter to retrieve.
§Returns
  • Option<String> - The value of the route parameter if it exists.
Source

pub fn get_route_param<T>(&self, name: T) -> String
where T: AsRef<str>,

Retrieves a specific route parameter by its name, panicking if not found.

§Arguments
  • T - The name of the route parameter to retrieve.
§Returns
  • String - The value of the route parameter if it exists.
§Panics
  • If the route parameter is not found.
Source

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

Returns the original wire request target before routing or query-map conversion.

§Returns
  • Option<String> - The unchanged path and query, or none for a manually constructed context.
Source

pub fn try_get_attribute<V, K>(&self, key: K) -> Option<V>
where V: AnySendSyncClone, K: AsRef<str>,

Attempts to retrieve a specific attribute by its key, casting it to the specified type.

The original request target is readable under its own key, because the framework stores it in its own field rather than in the attribute map.

§Arguments
  • K - The key of the attribute to retrieve.
§Returns
  • Option<V> - The attribute value if it exists and can be cast to the specified type.
Source

pub fn get_attribute<V, K>(&self, key: K) -> V
where V: AnySendSyncClone, K: AsRef<str>,

Retrieves a specific attribute by its key, casting it to the specified type, panicking if not found.

§Arguments
  • K - The key of the attribute to retrieve.
§Returns
  • V - The attribute value if it exists and can be cast to the specified type.
§Panics
  • If the attribute is not found.
Source

pub fn set_attribute<K, V>(&mut self, key: K, value: V) -> &mut Self
where K: AsRef<str>, V: AnySendSyncClone,

Sets an attribute in the context.

§Arguments
  • K - The key of the attribute to set.
  • V - The value of the attribute.
§Returns
  • &mut Self - A reference to the modified context.
Source

pub fn remove_attribute<K>(&mut self, key: K) -> &mut Self
where K: AsRef<str>,

Removes an attribute from the context.

§Arguments
  • K - The key of the attribute to remove.
§Returns
  • &mut Self - A reference to the modified context.
Source

pub fn clear_attribute(&mut self) -> &mut Self

Clears all attributes from the context.

§Returns
  • &mut Self - A reference to the modified context.
Source

pub fn set_task_panic(&mut self, panic_data: PanicData) -> &mut Self

Stores panic data for the current task context.

§Arguments
  • PanicData - The panic data specific to the current task.
§Returns
  • &mut Self - Reference to the modified context for method chaining.
Source

pub fn try_get_task_panic_data(&self) -> Option<PanicData>

Retrieves panic data associated with the current task.

§Returns
  • Option<PanicData> - Task panic data if a panic was caught during execution.
Source

pub fn get_task_panic_data(&self) -> PanicData

Retrieves panic data associated with the current task.

§Returns
  • PanicData - Task panic data if available.
§Panics
  • If no task panic data is found.
Source

pub fn try_get_request_error_data(&self) -> Option<RequestError>

Retrieves request error information if an error occurred during handling.

§Returns
  • Option<RequestError> - The request error information if an error was caught.
Source

pub fn get_request_error_data(&self) -> RequestError

Retrieves request error information if an error occurred during handling.

§Returns
  • RequestError - The request error information if an error was caught.
§Panics
  • If the request error information is not found.
Source§

impl Context

Source

pub fn get_request(&self) -> &Request

Source

pub fn get_mut_request(&mut self) -> &mut Request

Source

pub fn set_request(&mut self, val: Request) -> &mut Self

Source

pub fn get_response(&self) -> &Response

Source

pub fn get_mut_response(&mut self) -> &mut Response

Source

pub fn set_response(&mut self, val: Response) -> &mut Self

Source

pub fn get_route_params(&self) -> &RouteParams

Source

pub fn get_mut_route_params(&mut self) -> &mut RouteParams

Source

pub fn set_route_params(&mut self, val: RouteParams) -> &mut Self

Source

pub fn get_original_target(&self) -> String

Source

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

Source

pub fn get_attributes(&self) -> &ThreadSafeAttributeStore

Source

pub fn get_mut_attributes(&mut self) -> &mut ThreadSafeAttributeStore

Source

pub fn set_attributes(&mut self, val: ThreadSafeAttributeStore) -> &mut Self

Trait Implementations§

Source§

impl AsMut<Context> for Context

Implementation of AsMut trait for Context.

Source§

fn as_mut(&mut self) -> &mut Self

Converts &mut Context to &mut Context via memory address conversion.

§Returns
  • &mut Self - A mutable reference to the Context instance.
Source§

impl AsRef<Context> for Context

Implementation of AsRef trait for Context.

Source§

fn as_ref(&self) -> &Self

Converts &Context to &Context via memory address conversion.

§Returns
  • &Self - A reference to the Context instance.
Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

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 Context

Source§

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

Formats the struct fields as a debug struct, skipping excluded fields.

§Arguments
  • &mut std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • std::fmt::Result - Success or failure of the formatting operation.
Source§

impl Default for Context

Implementation of Default trait for Context.

Source§

fn default() -> Self

Creates a default Context instance.

§Returns
  • Context - A new context with default values and a static default server.
Source§

impl Display for Context

Source§

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

Formats the value using the standard debug format.

§Arguments
  • &mut std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • std::fmt::Result - Success or failure of the formatting operation.
Source§

impl Eq for Context

Implementation of Eq trait for Context.

Source§

impl From<&Context> for usize

Implementation of From trait for converting &Context into usize address.

Source§

fn from(ctx: &Context) -> Self

Converts a reference to Context into its memory address.

§Arguments
  • &Context - The reference to the Context instance.
§Returns
  • usize - The memory address of the Context instance.
Source§

impl From<&mut Context> for usize

Implementation of From trait for converting &mut Context into usize address.

Source§

fn from(ctx: &mut Context) -> Self

Converts a mutable reference to Context into its memory address.

§Arguments
  • &mut Context - The mutable reference to the Context instance.
§Returns
  • usize - The memory address of the Context instance.
Source§

impl From<usize> for &'static Context

Implementation of From trait for converting usize address into &Context.

Source§

fn from(address: usize) -> &'static Context

Converts a memory address into a reference to Context.

§Arguments
  • usize - The memory address of the Context instance.
§Returns
  • &'static Context - A reference to the Context at the given address.
§Safety
  • The address is guaranteed to be a valid Context instance that was previously converted from a reference and is managed by the runtime.
Source§

impl<'a> From<usize> for &'a mut Context

Implementation of From trait for converting usize address into &mut Context.

Source§

fn from(address: usize) -> &'a mut Context

Converts a memory address into a mutable reference to Context.

§Arguments
  • usize - The memory address of the Context instance.
§Returns
  • &'a mut Context - A mutable reference to the Context at the given address.
§Safety
  • The address is guaranteed to be a valid Context instance that was previously converted from a reference and is managed by the runtime.
Source§

impl Lifetime for Context

Implementation of Lifetime trait for Context.

Source§

unsafe fn leak(&self) -> &'static Self

Converts a reference to the context into a 'static reference.

§Returns
  • &'static Self - A reference to the context with a 'static lifetime.
§Safety
  • The address is guaranteed to be a valid Self instance that was previously converted from a reference and is managed by the runtime.
Source§

unsafe fn leak_mut(&self) -> &'static mut Self

Converts a reference to the context into a 'static mutable reference.

§Returns
  • &'static mut Self - A mutable reference to the context with a 'static lifetime.
§Safety
  • The address is guaranteed to be a valid Self instance that was previously converted from a reference and is managed by the runtime.
Source§

impl PartialEq for Context

Implementation of PartialEq trait for Context.

Source§

fn eq(&self, other: &Self) -> bool

Compares two Context instances for equality.

§Arguments
  • &Self - The first Context instance.
  • &Self - The second Context instance.
§Returns
  • bool - True if the instances are equal, otherwise false.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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