Fix compile time issues with Router::boxed
#385
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds
BoxRouterLayer
(created withBoxRouter::layer
) which is used to box routes and removesRouter::boxed
. Rust is apparently bad a checking trait bounds on functions (such asRouter::boxed
) but deals just fine with trait bounds inimpl
s 🤷Curiously doing
.layer(BoxRouter::layer())
is slow, but.layer(BoxRoute::<Body>::layer())
is fast even thoughBoxRouter
's first generic parameter defaults toBody
🤔 So the docs specifically call out using.layer(BoxRoute::<Body>::layer())
. I've tried making it required at compile time to always use a turbofish but haven't found a way.I still wanna do a bit more testing hence the draft. If things turn out to work well I think we should consider backporting this to 0.2 but deprecating
Router::boxed
instead of removing it.