pub struct Context(/* private fields */);Expand description
The main connection context, providing thread-safe access to connection data.
This is a wrapper around ContextData that uses an Arc<RwLock<ContextData>> to allow
for shared, mutable access across asynchronous tasks.
Implementations§
Source§impl Context
Implementation of methods for the Context structure.
impl Context
Implementation of methods for the Context structure.
Sourcepub async fn is_aborted(&self) -> bool
pub async fn is_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) -> &Self
pub async fn set_aborted(&self, aborted: bool) -> &Self
Sourcepub async fn cancel_abort(&self) -> &Self
pub async fn cancel_abort(&self) -> &Self
Sourcepub async fn is_closed(&self) -> bool
pub async fn is_closed(&self) -> bool
Checks if the connection has been closed.
§Returns
bool- True if the connection is closed, otherwise false.
Sourcepub async fn set_closed(&self, closed: bool) -> &Self
pub async fn set_closed(&self, closed: bool) -> &Self
Sourcepub async fn is_terminated(&self) -> bool
pub async 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 async fn try_get_stream(&self) -> Option<ArcRwLockStream>
pub async fn try_get_stream(&self) -> Option<ArcRwLockStream>
Sourcepub async fn get_stream(&self) -> ArcRwLockStream
pub async fn get_stream(&self) -> ArcRwLockStream
Sourcepub async fn set_stream(&self, stream: ArcRwLockStream) -> &Self
pub async fn set_stream(&self, stream: ArcRwLockStream) -> &Self
Sourcepub async fn get_request(&self) -> Request
pub async fn get_request(&self) -> Request
Sourcepub async fn set_request(&self, request: Request) -> &Self
pub async fn set_request(&self, request: Request) -> &Self
Sourcepub async fn get_response(&self) -> Response
pub async fn get_response(&self) -> Response
Sourcepub async fn set_response(&self, response: Response) -> &Self
pub async fn set_response(&self, response: Response) -> &Self
Sourcepub async fn try_get_socket_addr(&self) -> OptionSocketAddr
pub async fn try_get_socket_addr(&self) -> OptionSocketAddr
Attempts to get the socket address from the stream.
§Returns
OptionSocketAddr- The socket address if available.
Sourcepub async fn get_socket_addr(&self) -> SocketAddr
pub async fn get_socket_addr(&self) -> SocketAddr
Sourcepub async fn try_get_socket_addr_string(&self) -> Option<String>
pub async fn try_get_socket_addr_string(&self) -> Option<String>
Gets the socket address as a string.
§Returns
Option<String>- The socket address as a string if available.
Sourcepub async fn get_socket_addr_string(&self) -> String
pub async fn get_socket_addr_string(&self) -> String
Sourcepub async fn try_get_socket_host(&self) -> OptionSocketHost
pub async fn try_get_socket_host(&self) -> OptionSocketHost
Attempts to get the socket host (IP address).
§Returns
OptionSocketHost- The socket host if available.
Sourcepub async fn get_socket_host(&self) -> IpAddr
pub async fn get_socket_host(&self) -> IpAddr
Sourcepub async fn try_get_socket_port(&self) -> OptionSocketPort
pub async fn try_get_socket_port(&self) -> OptionSocketPort
Sourcepub async fn get_socket_port(&self) -> u16
pub async fn get_socket_port(&self) -> u16
Sourcepub async fn try_get_data<V, K>(&self, key: K) -> Option<V>
pub async fn try_get_data<V, K>(&self, key: K) -> Option<V>
Sourcepub async fn get_data_value<V, K>(&self, key: K) -> V
pub async fn get_data_value<V, K>(&self, key: K) -> V
Sourcepub async fn remove_data<K>(&self, key: K) -> &Self
pub async fn remove_data<K>(&self, key: K) -> &Self
Sourcepub async fn clear_data(&self) -> &Self
pub async fn clear_data(&self) -> &Self
Clears all data from the context’s data map.
§Returns
&Self- Reference to self for method chaining.
Sourcepub async fn try_send<D>(&self, data: D) -> ResponseResult
pub async fn try_send<D>(&self, data: D) -> ResponseResult
Sourcepub async fn try_flush(&self) -> ResponseResult
pub async fn try_flush(&self) -> ResponseResult
Sourcepub async fn try_shutdown(&self) -> ResponseResult
pub async fn try_shutdown(&self) -> ResponseResult
Attempts to shut down the stream.
§Returns
ResponseResult- Ok(()) on success, or an error on failure.
Trait Implementations§
Source§impl From<ArcRwLockStream> for Context
Implementation of From<ArcRwLockStream> for Context.
impl From<ArcRwLockStream> for Context
Implementation of From<ArcRwLockStream> for Context.
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin 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