Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve opaque error message for Handler::layer #1336

Merged
merged 1 commit into from
Aug 28, 2022
Merged

Conversation

davidpdrsn
Copy link
Member

Layers applied with Hander::layer must implement Clone. If they don't you get the familiar "Handler not implemented ..." error. Other methods like Router::layer doesn't require this and its pretty confusing why a layer would work on a router but not on a handler. I just spent an hour helping someone on Discord track this down 😅

The reason the Handler::layer requires L: Clone is that layers can only be applied to Services and turning a Handler into a Service requires the state. We don't have the state yet in Handler::layer so instead we store the layer with the handler and apply the layer in <Layered as Handler>::call.

@davidpdrsn davidpdrsn merged commit 3f92f7d into main Aug 28, 2022
@davidpdrsn davidpdrsn deleted the require-clone-early branch August 28, 2022 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants