Skip to content

A Tower Service combinator that "pipelines" two services

License

Notifications You must be signed in to change notification settings

davidpdrsn/tower-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tower-pipeline

Crates.io Docs dependency status Build status

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 analogous 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

About

A Tower Service combinator that "pipelines" two services

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages