feat(service): introduce hyper-specific Service
#1490
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces the
hyper::service
module, which replacestokio-service
.Since the trait is specific to hyper, its associated
types have been adjusted. It didn't make sense to need to define
Service<Request=http::Request>
, since we already know the context isHTTP. Instead, the request and response bodies are associated types now,
and slightly stricter bounds have been placed on
Error
.The helpers
service_fn
andservice_fn_ok
should be sufficient fornow to ease creating
Service
s.The
NewService
trait now allows service creation to also beasynchronous.
These traits are similar to
tower
in nature, and possibly will bereplaced completely by it in the future. For now, hyper defining its own
allows the traits to have better context, and prevents breaking changes
in
tower
from affecting hyper.Closes #1461
BREAKING CHANGE: The
Service
trait has changed: it has some changedassociated types, and
call
is now bound to&mut self
.The
NewService
trait has changed: it has some changed associatedtypes, and
new_service
now returns aFuture
.Client
no longer implementsService
for now.hyper::server::conn::Serve
now returnsConnecting
instead ofConnection
s, sincenew_service
can now return aFuture
. TheConnecting
is a future wrapping the new service future, returninga
Connection
afterwards. In many cases,Future::flatten
can beused.