udp 10.2.3

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

/// Default server hook.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DefaultServerHook;

/// Represents the hooks for managing the server's lifecycle, specifically for waiting and shutting down.
///
/// Accessors are generated by `#[derive(Data)]`; the hook getters return owned
/// `Arc` clones via `type(clone)`.
#[derive(Clone, Data)]
pub struct ServerControlHook {
    /// A hook that returns a future, which completes when the server's main task finishes.
    /// This is typically used to wait for the server to stop accepting connections before
    /// the application exits.
    #[get(type(clone))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) wait_hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
    /// A hook that, when called, initiates a graceful shutdown of the server.
    /// This will stop the server from accepting new connections and allow existing ones
    /// to complete.
    #[get(type(clone))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) shutdown_hook: Arc<dyn Fn() -> SendableAsyncTask<()> + Send + Sync>,
}

/// Represents the state associated with a single connection handler.
///
/// This struct encapsulates the necessary context for processing a connection,
/// including a reference to the network socket. It is created
/// for each connection and passed to the relevant handlers.
///
/// The socket getter is generated by `#[derive(Data)]` as an owned clone via
/// `type(clone)`; unused mutable accessors are skipped to avoid dead code.
#[derive(Clone, Data)]
pub(crate) struct HandlerState {
    /// A reference to the underlying network socket for the connection.
    #[get(pub(crate), type(clone))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(super) socket: ArcRwLockUdpSocket,
}