udp 10.2.2

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

/// Provides a default implementation for `ServerControlHook`.
impl Default for ServerControlHook {
    /// Creates a default `ServerControlHook` with no-op hooks.
    ///
    /// # Returns
    ///
    /// - `Self` - A new instance with default no-op hooks.
    #[inline(always)]
    fn default() -> Self {
        Self {
            wait_hook: Arc::new(|| Box::pin(async {})),
            shutdown_hook: Arc::new(|| Box::pin(async {})),
        }
    }
}

/// Implementation of methods for `ServerControlHook`.
impl ServerControlHook {
    /// Waits for the server to finish.
    pub async fn wait(&self) {
        (self.get_wait_hook())().await;
    }

    /// Shuts down the server.
    pub async fn shutdown(&self) {
        (self.get_shutdown_hook())().await;
    }
}

/// Implementation of methods for `HandlerState`.
impl HandlerState {
    /// Creates a new HandlerState instance.
    ///
    /// # Arguments
    ///
    /// - `ArcRwLockUdpSocket` - The network socket.
    ///
    /// # Returns
    ///
    /// - `Self` - The newly created handler state.
    #[inline(always)]
    pub(crate) fn new(socket: ArcRwLockUdpSocket) -> Self {
        Self { socket }
    }
}

/// Implementation of `ServerHook` for `DefaultServerHook`.
impl ServerHook for DefaultServerHook {
    /// Creates a new instance of `DefaultServerHook`.
    ///
    /// # Arguments
    ///
    /// - `&Context` - The request context (unused).
    ///
    /// # Returns
    ///
    /// A future that resolves to a new `DefaultServerHook` instance.
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    /// Executes the default hook's processing logic (no-op).
    ///
    /// # Arguments
    ///
    /// - `&Context` - The request context (unused).
    async fn handle(self, _ctx: &Context) {}
}