Skip to content

the trait for<'a> tower_service::Service<IncomingStream<'a>> is not implemented for Router<S> #2564

Answered by jplatte
buildwithzephyr asked this question in Q&A
Discussion options

You must be logged in to vote

You annotated the app binding with a type of Router<Arc<Struct>>. The (first) type parameter is for the state that needs to be supplied for the routes, .with_state changes that type parameter to any other state type that any routes added later might need. Before the router can be passed to serve, it must be transformed to a Router<()>.

You should be able to fix the problem by removing the type annotation, as in

let app = Router::new().route("/", get(handler)).with_state(state.clone());

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@ababo
Comment options

@ababo
Comment options

@jplatte
Comment options

@ababo
Comment options

@daniel1302
Comment options

Answer selected by jplatte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants