pub struct Context(/* private fields */);Expand description
The main application context, providing thread-safe access to request and response data.
This is a wrapper around ContextData that uses an Arc<RwLock<>> to allow
for shared, mutable access across asynchronous tasks.
Implementations§
Source§impl Context
Implementation of methods for Context.
impl Context
Implementation of methods for Context.
Sourcepub fn new(
socket: &ArcRwLockUdpSocket,
request: &Request,
client_addr: SocketAddr,
) -> Self
pub fn new( socket: &ArcRwLockUdpSocket, request: &Request, client_addr: SocketAddr, ) -> Self
Sourcepub async fn get_aborted(&self) -> bool
pub async fn get_aborted(&self) -> bool
Checks if the context has been marked as aborted.
§Returns
bool- True if the context is aborted, otherwise false.
Sourcepub async fn set_aborted(&self, aborted: bool)
pub async fn set_aborted(&self, aborted: bool)
Sourcepub async fn cancel_aborted(&self)
pub async fn cancel_aborted(&self)
Cancels the aborted state of the context.
Sourcepub async fn try_get_socket(&self) -> Option<ArcRwLockUdpSocket>
pub async fn try_get_socket(&self) -> Option<ArcRwLockUdpSocket>
Retrieves the underlying network socket, if available.
§Returns
Option<ArcRwLockUdpSocket>- The thread-safe, shareable network socket if it exists.
Sourcepub async fn get_socket(&self) -> ArcRwLockUdpSocket
pub async fn get_socket(&self) -> ArcRwLockUdpSocket
Sourcepub async fn get_request(&self) -> Request
pub async fn get_request(&self) -> Request
Sourcepub async fn get_response(&self) -> Response
pub async fn get_response(&self) -> Response
Sourcepub async fn try_get_client_addr(&self) -> Option<SocketAddr>
pub async fn try_get_client_addr(&self) -> Option<SocketAddr>
Retrieves the client address, if available.
§Returns
Option<SocketAddr>- The client address if present.
Sourcepub async fn get_client_addr(&self) -> SocketAddr
pub async fn get_client_addr(&self) -> SocketAddr
Sourcepub async fn try_get_client_addr_string(&self) -> Option<String>
pub async fn try_get_client_addr_string(&self) -> Option<String>
Retrieves the client address as a string.
§Returns
Option<String>- The string representation of the client address if available.
Sourcepub async fn try_get_client_host(&self) -> Option<IpAddr>
pub async fn try_get_client_host(&self) -> Option<IpAddr>
Sourcepub async fn try_get_client_port(&self) -> Option<u16>
pub async fn try_get_client_port(&self) -> Option<u16>
Sourcepub async fn set_attribute<K, V>(&self, key: K, value: V) -> &Self
pub async fn set_attribute<K, V>(&self, key: K, value: V) -> &Self
Sourcepub async fn try_get_attribute<V, K>(&self, key: K) -> Option<V>
pub async fn try_get_attribute<V, K>(&self, key: K) -> Option<V>
Sourcepub async fn get_attribute<V, K>(&self, key: K) -> V
pub async fn get_attribute<V, K>(&self, key: K) -> V
Sourcepub async fn remove_attribute<K>(&self, key: K) -> &Self
pub async fn remove_attribute<K>(&self, key: K) -> &Self
Sourcepub async fn clear_attributes(&self) -> &Self
pub async fn clear_attributes(&self) -> &Self
Sourcepub async fn send<T>(&self, data: T) -> ResponseResultwhere
T: Into<ResponseData>,
pub async fn send<T>(&self, data: T) -> ResponseResultwhere
T: Into<ResponseData>,
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more