Skip to main content

Context

Struct Context 

Source
pub struct Context { /* 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.

Implementations§

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
  • AsRef<str> - 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
  • AsRef<str> - 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 try_get_attribute<V>(&self, key: impl AsRef<str>) -> Option<V>

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

§Arguments
  • AsRef<str> - 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>(&self, key: impl AsRef<str>) -> V

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

§Arguments
  • AsRef<str> - The key of the attribute to retrieve.
§Returns
  • AnySendSyncClone - 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
  • AsRef<str> - The key of the attribute to set.
  • AnySendSyncClone - 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
  • AsRef<str> - 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 set_request(&mut self, val: Request) -> &mut Self

Source

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

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 set_route_params(&mut self, val: RouteParams) -> &mut Self

Source

pub fn get_route_params(&self) -> &RouteParams

Source

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

Source

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

Source

pub fn get_attributes(&self) -> &ThreadSafeAttributeStore

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 Context - 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
  • &Context - A reference to the Context instance.
Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 value using the given formatter. Read more
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 given formatter. Read more
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
  • &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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V