-
Notifications
You must be signed in to change notification settings - Fork 283
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
util: rework Either
#637
util: rework Either
#637
Conversation
Have you considered implementing |
Additionally, IIRC there was some talk about changing |
That would mean tower gets a public dependency on
Yeah that seems fine to me. I'll do that. |
FWIW, |
Actually implementing |
Oh, you're right, I didn't think through the orphan rules here. I don't think we'll be able to do that, then. We could use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good to me (in 0.5, of course)
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
I'm generally +1 on this. we should do 0.5 sooner than later... The CI failure seems legit, though. |
Tower already has `option_layer` for conditionally applying a `Layer` but since it uses `tower::util::Either` it always changes the error type to `BoxError`. That requires using `HandleErrorLayer` which is inconvenient for axum users. That has been changed in tower (tower-rs/tower#637) but still has some issues (tower-rs/tower#665). Its also a breaking change so hasn't been released yet. In the meantime I figure we can provide our own thing in axum-extra, since we already have an `Either` type there.
Tower already has `option_layer` for conditionally applying a `Layer` but since it uses `tower::util::Either` it always changes the error type to `BoxError`. That requires using `HandleErrorLayer` which is inconvenient for axum users. That has been changed in tower (tower-rs/tower#637) but still has some issues (tower-rs/tower#665). Its also a breaking change so hasn't been released yet. In the meantime I figure we can provide our own thing in axum-extra, since we already have an `Either` type there.
In practice I've found
Either
be hard to use since it changes the error type toBoxError
. That means if you combine two infallible services you get a service that, to the type system, is fallible. That doesn't work well with axum's error handling model which requires all services to be infallible and thus always return a response. So you end up having to add boilerplate just to please the type system.Additionally, the fact that
Either
implementsFuture
also means we cannot fully remove the dependency onpin-project
sincepin-project-lite
doesn't support tuple enum variants, only named fields.This PR reworks
Either
to address these:where B::Error: From<A::Error>
but I hope this simpler model will lead to better compiler errors.pin-project-lite
Future
impl so we can remove the dependency onpin-project
Goes without saying that this is a breaking change so we have to wait until tower 0.5 to ship this.
cc @jplatte
Fixes #594
Fixes #550