Skip to content

Making a generic router #2184

Answered by davidpdrsn
willburden asked this question in Q&A
Discussion options

You must be logged in to vote

You need to also make sure that R is Send + 'static:

trait Resource: DeserializeOwned + Send + 'static {}

fn resource_router<R: Resource>() -> Router {
    Router::new().route("/", get(get_resource::<R>))
}

async fn get_resource<R: Resource>(_: Json<R>) {}

The Send bound comes from the impl for Handler for functions that take one argument:

and the 'static bound comes from get:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by willburden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants