-
-
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
feat(server): add server::Builder::serve_service #2541
Conversation
/// } | ||
/// # } | ||
/// ``` | ||
pub fn serve_service<S, B>(self, service: S) -> Server<I, Shared<S>, E> |
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.
I don't think the name serve_service
is particularly good but couldn't come up with anything else.
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.
serve
?
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.
What if instead of a separate method, it's part of hyper::service
?
Server::bind(addr)
.serve(hyper::service::shared(svc))
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.
serve
?
serve
is already taken https://docs.rs/hyper/0.14.7/hyper/server/struct.Builder.html#method.serve 😞 This method is actually not on Server
but on server::Builder
. Fixing description now.
What if instead of a separate method, it's part of
hyper::service
?
I was thinking that since its such a common use case it made sense to have a dedicated method for it.
c6d6bfd
to
4931c8b
Compare
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
4931c8b
to
1f1c03b
Compare
I think instead of adding more methods to the |
We discussed this in Discord and decided to wait as a bigger change to Server is planned as part of either 0.15 or a potential 1.0. |
This adds
server::Builder::serve_service
which is a convenience for doingThat now becomes
It basically copies
tower::make::Shared
into Hyper so users don't needto add another dependency to do this.
Also adjusted the docs for
hyper::server
a bit to makeserver_service
the top example as I believe its the more common use-case.
Fixes #2154