-
Notifications
You must be signed in to change notification settings - Fork 264
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
NewService is generic over error #5
Conversation
Previously, NewService required returning a future yielding io::Error as the error. This is not needed and is restrictive.
What are the use cases for which My concern is basically that if you want to fold multiple fn two_service<A, B, E>(factory1: A, factory2: B) -> Join<A::Future, B::Future> where
A: NewService,
B: NewService,
A::Future: Future<Error = E>,
B::Future: Future<Error = E>,
{
factory1.new_service().join(factory2.new_service())
} A way to mitigate this would be to add yet another associated type to NewService, Not advocating any particular path, just see three options here (master, this branch, adding another assoc type) and they all have drawbacks. |
Well, one example would be a TLS handshake. I would say, in general, |
Also, in the back pressure example, |
Both great examples! I'm convinced. How do you feel about the difference between this PR and adding another associated type? On the one hand, Yet Another Associated Type, but I'm worried people are going to end up having to write |
@withoutboats would I would say that |
Right now, assoc types of assoc types are always treated as ambiguous, e.g. even this: trait Foo {
type Bar: Bar;
}
trait Bar {
type Baz;
}
fn foo<T: Foo>(_: T::Bar::Baz) { } I think this could be improved but right now that's the state of things unfortunately. |
@withoutboats do you have any ideas for how to name the associated type? |
|
@withoutboats I whichever is most common to address should be
|
I added It requires this in the impl now, which is a bit unfortunate: https://github.com/carllerche/tower/blob/65b8eea55a39b7934d5b73ab6dc424e4c985dde4/src/lib.rs#L219 |
type InitError = S::InitError; For the function impl, you could instead add an |
Previously, NewService required returning a future yielding io::Error as
the error. This is not needed and is restrictive.