tower-rs / tower

async fn(Request) -> Result<Response, Error>
https://docs.rs/tower
MIT License
3.56k stars 281 forks source link

Sharing Collections of Layers: BoxCloneLayer? #707

Closed alexrudy closed 2 years ago

alexrudy commented 2 years ago

Building a big stack of layers sometimes results in pretty long and unwieldily types, even with only a few layers, e.g. Stack<Either<TimeoutLayer, Identity>, Stack<Either<GlobalConcurrencyLimitLayer, Identity>, Stack<Either<LoadShedLayer, Identity>, Identity>>>

When working with such layers, BoxLayer can be useful, but only if you need a BoxService. If you want to produce a BoxCloneService, you are out of luck. Should tower add a BoxCloneLayer? Am I approaching this all wrong? I want to be able to combine several layers and pass them to a ServiceBuilder (e.g. Layers with a common configuration source) without having to write & edit a huge type every time.

LucioFranco commented 2 years ago

Yes, I think that totally makes sense. 👍