-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Provide convenience around serving ServiceFn
#2154
Comments
ServiceFn<fn(http::request::Request<hyper::body::body::Body>) -> impl std::future::Future {handler}, hyper::body::body::Body>
ServiceFn
I get what you mean, I even had filed something similar a while ago and never gotten back to it: tower-rs/tower#262 |
Tower recently got let server = Server::bind(&addr).serve(make_service_fn(|_| async move {
Ok::<_, Infallible>(service_fn(handler))
})); Into this let server = Server::bind(&addr).serve(Shared::new(service_fn(handler)); There is also an example in the hyper docs here https://docs.rs/hyper/0.14.7/hyper/server/index.html#example @rylev Do you think this is sufficient to close this? |
I would have preferred if Hyper had a solution that didn't require taking another dependency. The example is still not what I would call easy and intuitive to understand. |
Thats true. Having to pull in tower is unfortunate. I'm working on a proper fix. |
This adds `Server::serve_service` which is a convenience for doing ```rust Server::bind(&addr).serve(make_service_fn(|_| async move { Ok::<_, Infallible>(service_fn(handler)) })); ``` That now becomes ```rust Server::bind(&addr).serve_service(service_fn(handler)); ``` It basically copies [`tower::make::Shared`][] into Hyper so users don't need to add another dependency to do this. Fixes #2154 [`tower::make::Shared`]: https://docs.rs/tower/0.4.7/tower/make/struct.Shared.html
This adds `Server::serve_service` which is a convenience for doing ```rust Server::bind(&addr).serve(make_service_fn(|_| async move { Ok::<_, Infallible>(service_fn(handler)) })); ``` That now becomes ```rust Server::bind(&addr).serve_service(service_fn(handler)); ``` It basically copies [`tower::make::Shared`][] into Hyper so users don't need to add another dependency to do this. Fixes #2154 [`tower::make::Shared`]: https://docs.rs/tower/0.4.7/tower/make/struct.Shared.html
This adds `server::Builder::serve_service` which is a convenience for doing ```rust Server::bind(&addr).serve(make_service_fn(|_| async move { Ok::<_, Infallible>(service_fn(handler)) })); ``` That now becomes ```rust Server::bind(&addr).serve_service(service_fn(handler)); ``` It basically copies [`tower::make::Shared`][] into Hyper so users don't need to add another dependency to do this. Fixes #2154 [`tower::make::Shared`]: https://docs.rs/tower/0.4.7/tower/make/struct.Shared.html
The new What do you think about updating the "passing data" example or adding an extra example?
I think it can be simplified to this (assuming
|
We ended up not merging that PR #2541 |
😅 Oh I see! (Checking out #2321 linked in the PR...) |
When making a service to pass to
server
I've never usedmake_service_fn
in any other way than:It would be nice to be able to write:
or at least:
Thoughts?
The text was updated successfully, but these errors were encountered: