Function serve_async

Source
pub async fn serve_async<F, Fut>(
    addr: &str,
    dict: Arc<Dictionary>,
    secret: &str,
    handler: F,
) -> Result<(), Box<dyn Error>>
where F: Fn(RadiusPacket) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<RadiusPacket, String>> + Send,
Examples found in repository?
examples/server.rs (lines 15-30)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    // Load the RADIUS dictionary
11    let dict = Arc::new(Dictionary::load_embedded()?);
12    let secret = "test123";
13
14    // Start the RADIUS server using an async handler
15    serve_async("0.0.0.0:1812", dict, secret, move |packet| async move {
16        println!("🔍 Incoming ID {} from {:?}", packet.identifier, packet.username());
17
18        if let Some(username) = packet.username() {
19            if username.trim() == "ec:30:b3:6d:24:6a" {
20                Ok(packet.reply_accept(vec![
21                    RadiusAttribute::session_timeout(3600),
22                    RadiusAttribute::reply_message("Welcome, admin."),
23                ]))
24            } else {
25                Ok(packet.reply_reject("User not allowed"))
26            }
27        } else {
28            Ok(packet.reply_reject("Missing username"))
29        }
30    })
31    .await
32}