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 stream, request, response, and any custom attributes.

Implementations§

Source§

impl Context

Implementation of methods for Context structure.

Source

pub async fn http_from_stream(&mut self) -> Result<Request, RequestError>

Reads an HTTP request from the underlying stream.

§Returns
  • Result<Request, RequestError> - The parsed request or error.
Source

pub async fn ws_from_stream(&mut self) -> Result<Request, RequestError>

Reads a WebSocket frame from the underlying stream.

§Returns
  • Result<Request, RequestError> - The parsed frame or error.
Source

pub fn is_terminated(&self) -> bool

Checks if the connection has been terminated (aborted or closed).

§Returns
  • bool - True if the connection is either aborted or closed, otherwise false.
Source

pub async fn try_get_socket_addr(&self) -> Option<SocketAddr>

Retrieves the remote socket address of the connection.

§Returns
  • Option<SocketAddr> - The socket address of the remote peer if available.
Source

pub async fn get_socket_addr(&self) -> SocketAddr

Retrieves the remote socket address.

§Returns
  • SocketAddr - The socket address of the remote peer.
§Panics
  • If the socket address is not found.
Source

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

Retrieves the remote socket address as a string.

§Returns
  • Option<String> - The string representation of the socket address if available.
Source

pub async fn get_socket_addr_string(&self) -> String

Retrieves the remote socket address as a string.

§Returns
  • String - The string representation of the socket address.
§Panics
  • If the socket address is not found.
Source

pub async fn try_get_socket_host(&self) -> Option<SocketHost>

Retrieves the IP address part of the remote socket address.

§Returns
  • Option<SocketHost> - The IP address of the remote peer.
Source

pub async fn get_socket_host(&self) -> SocketHost

Retrieves the IP address part of the remote socket address.

§Returns
  • SocketHost - The IP address of the remote peer.
§Panics
  • If the socket address is not found.
Source

pub async fn try_get_socket_port(&self) -> Option<SocketPort>

Retrieves the port number part of the remote socket address.

§Returns
  • Option<SocketPort> - The port number of the remote peer if available.
Source

pub async fn get_socket_port(&self) -> SocketPort

Retrieves the port number part of the remote socket address.

§Returns
  • SocketPort - The port number of the remote peer.
§Panics
  • If the socket address is not found.
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 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

pub async fn try_send(&mut self) -> Result<(), ResponseError>

Sends HTTP response data over the stream.

§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send(&mut self)

Sends HTTP response data over the stream.

§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body(&self) -> Result<(), ResponseError>

Sends HTTP response body.

§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send_body(&self)

Sends HTTP response body.

§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body_with_data<D>( &self, data: D, ) -> Result<(), ResponseError>
where D: AsRef<[u8]>,

Sends only the response body to the client with additional data.

This method is useful for streaming data or for responses where headers have already been sent.

§Arguments
  • AsRef<[u8]> - The additional data to send as the body.
§Returns
  • Result<(), ResponseError> - The result of the send operation.
Source

pub async fn send_body_with_data<D>(&self, data: D)
where D: AsRef<[u8]>,

Sends HTTP response body.

§Arguments
  • AsRef<[u8]> - The response body data (must implement AsRef<u8>).
§Panics

Panics if the write operation fails.

Source

pub async fn try_send_body_list<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple HTTP response bodies sequentially.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The response body data list to send.
§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send_body_list<I, D>(&self, data_iter: I)
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple HTTP response bodies sequentially.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The response body data list to send.
§Panics

Panics if any write operation fails.

Source

pub async fn try_send_body_list_with_data<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends a list of response bodies to the client with additional data.

This is useful for streaming multiple data chunks or for responses where headers have already been sent.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The additional data to send as a list of bodies.
§Returns
  • Result<(), ResponseError> - The result of the send operation.
Source

pub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends a list of response bodies to the client with additional data.

§Arguments
  • I: IntoIterator<Item = D>, D: AsRef<[u8]> - The additional data to send as a list of bodies.
§Panics

Panics if any write operation fails.

Source

pub async fn try_flush(&self) -> Result<(), ResponseError>

Flushes the underlying network stream, ensuring all buffered data is sent.

§Returns
  • Result<(), ResponseError> - The result of the flush operation.
Source

pub async fn flush(&self)

Flushes all buffered data to the stream.

§Panics

Panics if the flush operation fails.

Source§

impl Context

Source

pub fn get_aborted(&self) -> bool

Source

pub fn get_mut_aborted(&mut self) -> &mut bool

Source

pub fn set_aborted(&mut self, val: bool) -> &mut Self

Source

pub fn get_closed(&self) -> bool

Source

pub fn get_mut_closed(&mut self) -> &mut bool

Source

pub fn set_closed(&mut self, val: bool) -> &mut Self

Source

pub fn get_request(&self) -> &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 get_route_params(&self) -> &RouteParams

Source

pub fn get_attributes(&self) -> &ThreadSafeAttributeStore

Source

pub fn get_server(&self) -> &ArcServer

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

Source§

fn default() -> Context

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

impl Display for Context

Source§

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

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

impl From<&ArcRwLockStream> for Context

Implementation of From trait for converting &ArcRwLockStream into Context.

Source§

fn from(stream: &ArcRwLockStream) -> Self

Converts a reference to a network stream into a Context with default request.

§Arguments
  • &ArcRwLockStream - The network stream reference to convert.
§Returns
  • Context - The newly created context instance.
Source§

impl From<ArcRwLockStream> for Context

Implementation of From trait for converting ArcRwLockStream into Context.

Source§

fn from(stream: ArcRwLockStream) -> Self

Converts a network stream into a Context with default request.

§Arguments
  • ArcRwLockStream - The network stream to convert.
§Returns
  • Context - The newly created context instance.
Source§

impl From<Server> for Context

Implementation of From trait for Context from Server.

Source§

fn from(server: Server) -> Self

Converts a Server into a Context with default request and response.

§Arguments
  • Server - The server to convert.
§Returns
  • Context - The newly created context instance.
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 · 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.
Source§

impl Eq for Context

Implementation of Eq trait for Context.

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

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> ErasedDestructor for T
where T: 'static,