Skip to content

Make type inference work for ServiceExt#566

Merged
jplatte merged 1 commit intomainfrom
jplatte/service-ext-type-inference
May 10, 2025
Merged

Make type inference work for ServiceExt#566
jplatte merged 1 commit intomainfrom
jplatte/service-ext-type-inference

Conversation

@jplatte
Copy link
Copy Markdown
Member

@jplatte jplatte commented May 9, 2025

Unfortunately, making type inference work for this requires removing the generic parameter from ServiceExt, which in turn requires removing the tower::Service supertrait. This made the Sealed trait useless, and while I was at it I also removed the Sized supertrait in favor of Sized bounds on all current trait methods (this allows backwards-compatibly adding methods that don't require Self to be Sized to be added).

This means that now you can call all of these methods on anything, the resulting type just isn't going to be very useful if the type you're calling the method on isn't a tower::Service<http::Request<B>> (extra bounds may apply depending on the exact method).

I also tested that this works in a real-world setting.
I think the only realistic alternative to this is not having ServiceExt at all.

Unfortunately, making type inference work for this requires removing the
generic parameter from ServiceExt, which in turn requires removing the
tower::Service supertrait. This made the Sealed trait useless, and while
I was at it I also removed the Sized supertrait in favor of Sized bounds
on all current trait methods (this allows backwards-compatibly adding
methods that don't require Self to be Sized to be added).

This means that now you can call all of these methods on _anything_, the
resulting type just isn't going to be very useful if the type you're
calling the method on isn't a tower::Service<http::Request<B>> (extra
bounds may apply depending on the exact method).
@seanmonstar
Copy link
Copy Markdown
Collaborator

Just curious, I didn't see an issue or someone point out compilation errors. Is there an example somewhere of what was broken?

@jplatte
Copy link
Copy Markdown
Member Author

jplatte commented May 9, 2025

Type inference couldn't figure out R when you chained these methods with the previous definition. I saw the same thing with tower's ServiceExt actually. Try to use one of its methods on a ServeDir.

@jplatte jplatte merged commit 2608a51 into main May 10, 2025
11 checks passed
@jplatte jplatte deleted the jplatte/service-ext-type-inference branch May 10, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants