Crates.io | tower-pipeline |
lib.rs | tower-pipeline |
version | 0.1.0 |
source | src |
created_at | 2021-02-06 20:56:44.885159 |
updated_at | 2021-02-06 20:56:44.885159 |
description | A Tower Service combinator that "pipelines" two services |
homepage | https://github.com/davidpdrsn/tower-pipeline |
repository | https://github.com/davidpdrsn/tower-pipeline |
max_upload_size | |
id | 351670 |
size | 11,162 |
A Tower Service
combinator that "pipelines" two services.
A [Pipeline
] is a Service
consisting of two other Service
s 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