Struct Context

Source
pub struct Context(/* private fields */);
Expand description

Context structure.

Wraps InnerContext providing thread-safe shared access.

Implementations§

Source§

impl Context

Provides thread-safe access and manipulation of the context.

Source

pub async fn get_read_lock(&self) -> RwLockReadContext<'_>

Gets a read lock for the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • RwLockReadContext - A read guard for the inner context.
Source

pub async fn get_write_lock(&self) -> RwLockWriteContext<'_>

Gets a write lock for the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • RwLockWriteContext - A write guard for the inner context.
Source

pub async fn get(&self) -> InnerContext

Gets a clone of the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • InnerContext - A cloned inner context.
Source

pub async fn get_stream(&self) -> OptionArcRwLockStream

Gets the stream from the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • OptionArcRwLockStream - The optional stream.
Source

pub async fn get_request(&self) -> Request

Gets the request from the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • Request - The request object.
Source

pub async fn get_response(&self) -> Response

Gets the response from the inner context.

§Arguments
  • &self - A reference to the Context.
§Returns
  • Response - The response object.
Source

pub async fn get_socket_addr(&self) -> OptionSocketAddr

Gets the socket address from the stream.

§Arguments
  • &self - A reference to the Context.
§Returns
  • OptionSocketAddr - The optional socket address.
Source

pub async fn get_socket_addr_or_default(&self) -> SocketAddr

Gets the socket address or a default if none is available.

§Arguments
  • &self - A reference to the Context.
§Returns
  • SocketAddr - The socket address or the default socket address.
Source

pub async fn get_socket_addr_string(&self) -> Option<String>

Gets the socket address as a string.

§Arguments
  • &self - A reference to the Context.
§Returns
  • Option<String> - The socket address as a string, if available.
Source

pub async fn get_socket_addr_or_default_string(&self) -> String

Gets the socket address as a string, or a default string if none is available.

§Arguments
  • &self - A reference to the Context.
§Returns
  • String - The socket address as a string, or the default socket address string.
Source

pub async fn get_socket_host(&self) -> OptionSocketHost

Gets the socket host from the socket address.

§Arguments
  • &self - A reference to the Context.
§Returns
  • OptionSocketHost - The optional socket host.
Source

pub async fn get_socket_port(&self) -> OptionSocketPort

Gets the socket port from the socket address.

§Arguments
  • &self - A reference to the Context.
§Returns
  • OptionSocketPort - The optional socket port.
Source

pub async fn send<T: Into<ResponseData>>(&self, data: T) -> ResponseResult

Sends data through the stream.

§Arguments
  • &self - A reference to the Context.
  • data - The data to send, which can be converted into ResponseData.
§Returns
  • ResponseResult - Ok(()) on success, or an error if the stream is not found or sending fails.
Source

pub async fn close(&self) -> ResponseResult

Closes the stream.

§Arguments
  • &self - A reference to the Context.
§Returns
  • ResponseResult - Ok(()) on success, or an error if the stream is not found or closing fails.
Source

pub async fn flush(&self) -> ResponseResult

Flushes the stream.

§Arguments
  • &self - A reference to the Context.
§Returns
  • ResponseResult - Ok(()) on success, or an error if the stream is not found or flushing fails.
Source

pub async fn set_data_value<T: Any + Send + Sync + Clone>( &self, key: &str, value: &T, ) -> &Self

Sets a data value in the context’s data map.

§Arguments
  • &self - A reference to the Context.
  • key - The key for the data.
  • value - The value to set, which must be cloneable and thread-safe.
§Returns
  • &Self - A reference to the Context.
Source

pub async fn get_data_value<T: Any + Send + Sync + Clone>( &self, key: &str, ) -> Option<T>

Gets a data value from the context’s data map.

§Arguments
  • &self - A reference to the Context.
  • key - The key for the data.
§Returns
  • Option<T> - The data value if found and successfully downcasted, otherwise None.
Source

pub async fn remove_data_value(&self, key: &str) -> &Self

Removes a data value from the context’s data map.

§Arguments
  • &self - A reference to the Context.
  • key - The key of the data to remove.
§Returns
  • &Self - A reference to the Context.
Source

pub async fn clear_data(&self) -> &Self

Clears all data from the context’s data map.

§Arguments
  • &self - A reference to the Context.
§Returns
  • &Self - A reference to the Context.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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> 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> 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> 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 = 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.