#tower-service #service #future #async

tower-pipeline

A Tower Service combinator that "pipelines" two services

1 unstable release

0.1.0 Feb 6, 2021

#1337 in Asynchronous

Download history 13/week @ 2024-07-26 4/week @ 2024-08-02 17/week @ 2024-08-23 7/week @ 2024-08-30 29/week @ 2024-09-06 111/week @ 2024-09-13 125/week @ 2024-09-20 120/week @ 2024-09-27 87/week @ 2024-10-04 5/week @ 2024-10-11 23/week @ 2024-10-18 1/week @ 2024-10-25

153 downloads per month

MIT license

10KB
142 lines

tower-pipeline

A Tower Service combinator that "pipelines" two services.

A Pipeline is a Service consisting of two other Services where the response of the first is the request of the second. This is analagous to function composition but for services.

use tower_pipeline::PipelineExt;
use tower::{service_fn, BoxError, ServiceExt};

// service that returns the length of a string
let length_svc = service_fn(|input: &'static str| async move {
    Ok::<_, BoxError>(input.len())
});

// service that doubles its input
let double_svc = service_fn(|input: usize| async move {
    Ok::<_, BoxError>(input * 2)
});

// combine our two services
let combined = length_svc.pipeline(double_svc);

// call the service
let result = combined.oneshot("rust").await.unwrap();

assert_eq!(result, 8);

License: MIT


lib.rs:

A Tower Service combinator that "pipelines" two services.

A Pipeline is a Service consisting of two other Services where the response of the first is the request of the second. This is analagous to function composition but for services.

use tower_pipeline::PipelineExt;
use tower::{service_fn, BoxError, ServiceExt};

// service that returns the length of a string
let length_svc = service_fn(|input: &'static str| async move {
    Ok::<_, BoxError>(input.len())
});

// service that doubles its input
let double_svc = service_fn(|input: usize| async move {
    Ok::<_, BoxError>(input * 2)
});

// combine our two services
let combined = length_svc.pipeline(double_svc);

// call the service
let result = combined.oneshot("rust").await.unwrap();

assert_eq!(result, 8);

Dependencies

~540–730KB
~14K SLoC