3 releases (breaking)

Uses new Rust 2024

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

#1239 in Rust patterns

Download history 63/week @ 2025-05-26 211/week @ 2025-06-02 84/week @ 2025-06-09 776/week @ 2025-06-16 540/week @ 2025-06-23 476/week @ 2025-06-30 624/week @ 2025-07-07 1219/week @ 2025-07-14 951/week @ 2025-07-21 3160/week @ 2025-07-28 842/week @ 2025-08-04 957/week @ 2025-08-11 274/week @ 2025-08-18 137/week @ 2025-08-25 214/week @ 2025-09-01 499/week @ 2025-09-08

1,130 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

32KB
809 lines

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");


async traits for xitca

No runtime deps