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.
impl Context
Implementation of methods for Context structure.
Sourcepub async fn http_from_stream(&mut self) -> Result<Request, RequestError>
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.
Sourcepub async fn ws_from_stream(&mut self) -> Result<Request, RequestError>
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.
Sourcepub fn is_terminated(&self) -> bool
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.
Sourcepub fn try_get_route_param<T>(&self, name: T) -> Option<String>
pub fn try_get_route_param<T>(&self, name: T) -> Option<String>
Sourcepub fn get_route_param<T>(&self, name: T) -> String
pub fn get_route_param<T>(&self, name: T) -> String
Sourcepub fn try_get_attribute<V>(&self, key: impl AsRef<str>) -> Option<V>where
V: AnySendSyncClone,
pub fn try_get_attribute<V>(&self, key: impl AsRef<str>) -> Option<V>where
V: AnySendSyncClone,
Sourcepub fn get_attribute<V>(&self, key: impl AsRef<str>) -> Vwhere
V: AnySendSyncClone,
pub fn get_attribute<V>(&self, key: impl AsRef<str>) -> Vwhere
V: AnySendSyncClone,
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.
Sourcepub fn set_attribute<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn set_attribute<K, V>(&mut self, key: K, value: V) -> &mut Self
Sourcepub fn remove_attribute<K>(&mut self, key: K) -> &mut Self
pub fn remove_attribute<K>(&mut self, key: K) -> &mut Self
Sourcepub fn clear_attribute(&mut self) -> &mut Self
pub fn clear_attribute(&mut self) -> &mut Self
Sourcepub fn try_get_task_panic_data(&self) -> Option<PanicData>
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.
Sourcepub fn get_task_panic_data(&self) -> PanicData
pub fn get_task_panic_data(&self) -> PanicData
Sourcepub fn try_get_request_error_data(&self) -> Option<RequestError>
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.
Sourcepub fn get_request_error_data(&self) -> RequestError
pub fn get_request_error_data(&self) -> RequestError
Sourcepub async fn try_send(&mut self) -> Result<(), ResponseError>
pub async fn try_send(&mut self) -> Result<(), ResponseError>
Sends HTTP response data over the stream.
§Returns
Result<(), ResponseError>- Result indicating success or failure.
Sourcepub async fn try_send_body(&self) -> Result<(), ResponseError>
pub async fn try_send_body(&self) -> Result<(), ResponseError>
Sends HTTP response body.
§Returns
Result<(), ResponseError>- Result indicating success or failure.
Sourcepub async fn try_send_body_with_data<D>(
&self,
data: D,
) -> Result<(), ResponseError>
pub async fn try_send_body_with_data<D>( &self, data: D, ) -> Result<(), ResponseError>
Sourcepub async fn send_body_with_data<D>(&self, data: D)
pub async fn send_body_with_data<D>(&self, data: D)
Sourcepub async fn try_send_body_list<I, D>(
&self,
data_iter: I,
) -> Result<(), ResponseError>
pub async fn try_send_body_list<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
Sourcepub async fn send_body_list<I, D>(&self, data_iter: I)
pub async fn send_body_list<I, D>(&self, data_iter: I)
Sourcepub async fn try_send_body_list_with_data<I, D>(
&self,
data_iter: I,
) -> Result<(), ResponseError>
pub async fn try_send_body_list_with_data<I, D>( &self, data_iter: I, ) -> Result<(), ResponseError>
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.
Sourcepub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
pub async fn send_body_list_with_data<I, D>(&self, data_iter: I)
Source§impl Context
impl Context
pub fn get_aborted(&self) -> bool
pub fn get_mut_aborted(&mut self) -> &mut bool
pub fn set_aborted(&mut self, val: bool) -> &mut Self
pub fn get_closed(&self) -> bool
pub fn get_mut_closed(&mut self) -> &mut bool
pub fn set_closed(&mut self, val: bool) -> &mut Self
pub fn get_stream(&self) -> ArcRwLockStream
pub fn try_get_stream(&self) -> &Option<ArcRwLockStream>
pub fn get_request(&self) -> &Request
pub fn get_response(&self) -> &Response
pub fn get_mut_response(&mut self) -> &mut Response
pub fn set_response(&mut self, val: Response) -> &mut Self
pub fn get_route_params(&self) -> &RouteParams
pub fn get_attributes(&self) -> &ThreadSafeAttributeStore
pub fn get_server(&self) -> &&'static Server
Trait Implementations§
Source§impl From<&ArcRwLockStream> for Context
Implementation of From trait for converting &ArcRwLockStream into Context.
impl From<&ArcRwLockStream> for Context
Implementation of From trait for converting &ArcRwLockStream into Context.
Source§impl From<&Context> for usize
Implementation of From trait for converting &Context into usize address.
impl From<&Context> for usize
Implementation of From trait for converting &Context into usize address.
Source§impl From<&'static Server> for Context
Implementation of From trait for Context from &'static Server.
impl From<&'static Server> for Context
Implementation of From trait for Context from &'static Server.
Source§impl From<&mut Context> for usize
Implementation of From trait for converting &mut Context into usize address.
impl From<&mut Context> for usize
Implementation of From trait for converting &mut Context into usize address.
Source§impl From<ArcRwLockStream> for Context
Implementation of From trait for converting ArcRwLockStream into Context.
impl From<ArcRwLockStream> for Context
Implementation of From trait for converting ArcRwLockStream into Context.
Source§impl From<usize> for &'static Context
Implementation of From trait for converting usize address into &Context.
impl From<usize> for &'static Context
Implementation of From trait for converting usize address into &Context.
Source§impl<'a> From<usize> for &'a mut Context
Implementation of From trait for converting usize address into &mut Context.
impl<'a> From<usize> for &'a mut Context
Implementation of From trait for converting usize address into &mut Context.
Source§impl From<usize> for Context
Implementation of From trait for converting usize address into Context.
impl From<usize> for Context
Implementation of From trait for converting usize address into Context.
Source§impl PartialEq for Context
Implementation of PartialEq trait for Context.
impl PartialEq for Context
Implementation of PartialEq trait for Context.
impl Eq for Context
Implementation of Eq trait for Context.