3 releases (breaking)

Uses new Rust 2024

new 0.3.0 Mar 12, 2025
0.2.0 Jul 24, 2024
0.1.0 Dec 29, 2023

#5 in #xitca-web

Download history 20/week @ 2024-11-23 40/week @ 2024-11-30 72/week @ 2024-12-07 97/week @ 2024-12-14 53/week @ 2024-12-21 13/week @ 2024-12-28 91/week @ 2025-01-04 96/week @ 2025-01-11 28/week @ 2025-01-18 141/week @ 2025-01-25 446/week @ 2025-02-01 280/week @ 2025-02-08 184/week @ 2025-02-15 280/week @ 2025-02-22 296/week @ 2025-03-01 224/week @ 2025-03-08

1,013 downloads per month
Used in 4 crates (3 directly)

Apache-2.0

32KB
809 lines

async traits for xitca


lib.rs:

traits for composable async functions.

Examples

use core::convert::Infallible;

use xitca_service::{fn_service, Service, ServiceExt};
// apply middleware to async function as service.
let builder = fn_service(|req: String| async { Ok::<_, Infallible>(req) })
    // a middleware function that has ownership of the argument and output of S as Service
    // trait implementor.
    .enclosed_fn(async |service, req| {
        service.call(req).await.map(|mut res| {
            res.push_str("-dagongren");
            res
        })
    });

// build the composited service.
let service = builder.call(()).await?;

// execute the service function with string argument.
let res = service.call("996".to_string()).await?;

assert_eq!(res, "996-dagongren");

No runtime deps