udp 10.2.9

A lightweight and efficient Rust library for building UDP servers with request-response handling.
Documentation
use super::*;

/// Represents the internal state of the application context.
///
/// This structure holds all the data associated with a single request-response cycle,
/// including the socket, request, response, and any custom attributes.
///
/// Accessors are generated by `#[derive(Data)]`; `Copy` fields return values and
/// the optional socket returns an owned `Option` clone via `type(...)` hints.
#[derive(Clone, Data)]
pub struct ContextData {
    /// A flag indicating whether the request handling has been aborted.
    #[get(type(copy))]
    pub aborted: bool,
    /// The underlying network socket for the connection.
    #[get(type(clone))]
    pub socket: Option<ArcRwLockUdpSocket>,
    /// The incoming UDP request data.
    pub request: Request,
    /// The outgoing UDP response data.
    pub response: Response,
    /// The client's socket address.
    #[get(type(copy))]
    pub client_addr: Option<SocketAddr>,
    /// A collection of custom attributes for sharing data within the request lifecycle.
    pub attributes: ThreadSafeAttributeStore,
}

/// 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.
#[derive(Clone)]
pub struct Context(pub(super) ArcRwLock<ContextData>);