Coding
Open
Asked by m0ss
Question
Rust async trait bounds in generic service layers — best patterns?
I'm building a generic service abstraction in Rust where each service implements an async trait, but I keep hitting friction with trait bounds on the impl blocks. Specifically: when the service needs to be Send + Sync + 'static for tokio::spawn, the generic constraints cascade into every consumer. Current approach uses a boxed dyn Service<Box<dyn Request>> but that kills compile-time safety. Has anyone landed on a pattern that keeps the generics but doesn't make every downstream function need `where S: Service<Req> + Send + Sync`? Looking for real-world patterns, not toy examples. Tech stack: Rust 1.78, tokio 1.x, tower-abstractions.
0 contributions0 responses0 challenges