Skip to content

Commit 7a28893

Browse files
committed
feat(service): rename Service to HttpService, re-export tower::Service`
The only important trait for a user is the `tower::Service` trait, which is now available also at `hyper::service::Service`. The other "trait aliases" are no longer publicly exported, as people thought they had to implement them. Also removes dependency on `tower-make`, which is trivial but otherwise shouldn't affect anyone. Closes #1959
1 parent ca5836f commit 7a28893

File tree

13 files changed

+251
-266
lines changed

13 files changed

+251
-266
lines changed

Diff for: Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ log = "0.4"
3434
pin-project = "0.4"
3535
time = "0.1"
3636
tower-service = "=0.3.0-alpha.2"
37-
tower-make = { version = "=0.3.0-alpha.2a", features = ['io'] }
3837
tokio-executor = "=0.2.0-alpha.6"
3938
tokio-io = "=0.2.0-alpha.6"
4039
tokio-sync = "=0.2.0-alpha.6"

Diff for: src/client/service.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
//! Utilities used to interact with the Tower ecosystem.
22
//!
3-
//! This module provides exports of `Service`, `MakeService` and `Connect` which
4-
//! all provide hook-ins into the Tower ecosystem.
3+
//! This module provides `Connect` which hook-ins into the Tower ecosystem.
54
6-
use super::conn::{SendRequest, Builder};
75
use std::marker::PhantomData;
8-
use crate::{common::{Poll, task, Pin}, body::Payload};
96
use std::future::Future;
107
use std::error::Error as StdError;
11-
use tower_make::MakeConnection;
128

13-
pub use tower_service::Service;
14-
pub use tower_make::MakeService;
9+
use crate::{common::{Poll, task, Pin}, body::Payload, service::{MakeConnection, Service}};
10+
use super::conn::{SendRequest, Builder};
1511

1612
/// Creates a connection via `SendRequest`.
1713
///

Diff for: src/common/exec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use tokio_executor::{SpawnError, TypedExecutor};
88
use crate::body::{Payload, Body};
99
use crate::proto::h2::server::H2Stream;
1010
use crate::server::conn::spawn_all::{NewSvcTask, Watcher};
11-
use crate::service::Service;
11+
use crate::service::HttpService;
1212

1313
pub trait H2Exec<F, B: Payload>: Clone {
1414
fn execute_h2stream(&mut self, fut: H2Stream<F, B>) -> crate::Result<()>;
1515
}
1616

17-
pub trait NewSvcExec<I, N, S: Service<Body>, E, W: Watcher<I, S, E>>: Clone {
17+
pub trait NewSvcExec<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>>: Clone {
1818
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()>;
1919
}
2020

@@ -119,7 +119,7 @@ where
119119
impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for Exec
120120
where
121121
NewSvcTask<I, N, S, E, W>: Future<Output=()> + Send + 'static,
122-
S: Service<Body>,
122+
S: HttpService<Body>,
123123
W: Watcher<I, S, E>,
124124
{
125125
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()> {
@@ -148,7 +148,7 @@ impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for E
148148
where
149149
E: TypedExecutor<NewSvcTask<I, N, S, E, W>> + Clone,
150150
NewSvcTask<I, N, S, E, W>: Future<Output=()>,
151-
S: Service<Body>,
151+
S: HttpService<Body>,
152152
W: Watcher<I, S, E>,
153153
{
154154
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()> {

Diff for: src/proto/h1/dispatch.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::body::{Body, Payload};
88
use crate::common::{Future, Never, Poll, Pin, Unpin, task};
99
use crate::proto::{BodyLength, DecodedLength, Conn, Dispatched, MessageHead, RequestHead, RequestLine, ResponseHead};
1010
use super::Http1Transaction;
11-
use crate::service::Service;
11+
use crate::service::HttpService;
1212

1313
pub(crate) struct Dispatcher<D, Bs: Payload, I, T> {
1414
conn: Conn<I, Bs::Data, T>,
@@ -29,7 +29,7 @@ pub(crate) trait Dispatch {
2929
fn should_poll(&self) -> bool;
3030
}
3131

32-
pub struct Server<S: Service<B>, B> {
32+
pub struct Server<S: HttpService<B>, B> {
3333
in_flight: Pin<Box<Option<S::Future>>>,
3434
pub(crate) service: S,
3535
}
@@ -407,7 +407,7 @@ impl<'a, T> Drop for OptGuard<'a, T> {
407407

408408
impl<S, B> Server<S, B>
409409
where
410-
S: Service<B>,
410+
S: HttpService<B>,
411411
{
412412
pub fn new(service: S) -> Server<S, B> {
413413
Server {
@@ -422,11 +422,11 @@ where
422422
}
423423

424424
// Service is never pinned
425-
impl<S: Service<B>, B> Unpin for Server<S, B> {}
425+
impl<S: HttpService<B>, B> Unpin for Server<S, B> {}
426426

427427
impl<S, Bs> Dispatch for Server<S, Body>
428428
where
429-
S: Service<Body, ResBody=Bs>,
429+
S: HttpService<Body, ResBody=Bs>,
430430
S::Error: Into<Box<dyn StdError + Send + Sync>>,
431431
Bs: Payload,
432432
{

Diff for: src/proto/h2/server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use crate::common::exec::H2Exec;
1111
use crate::common::{Future, Pin, Poll, task};
1212
use crate::headers;
1313
use crate::headers::content_length_parse_all;
14-
use crate::service::Service;
14+
use crate::service::HttpService;
1515
use crate::proto::Dispatched;
1616
use super::{PipeToSendStream, SendBuf};
1717

1818
use crate::{Body, Response};
1919

2020
pub(crate) struct Server<T, S, B, E>
2121
where
22-
S: Service<Body>,
22+
S: HttpService<Body>,
2323
B: Payload,
2424
{
2525
exec: E,
@@ -28,7 +28,7 @@ where
2828
}
2929

3030
// TODO: fix me
31-
impl<T, S: Service<Body>, B: Payload, E> Unpin for Server<T, S, B, E> {}
31+
impl<T, S: HttpService<Body>, B: Payload, E> Unpin for Server<T, S, B, E> {}
3232

3333
enum State<T, B>
3434
where
@@ -51,7 +51,7 @@ where
5151
impl<T, S, B, E> Server<T, S, B, E>
5252
where
5353
T: AsyncRead + AsyncWrite + Unpin,
54-
S: Service<Body, ResBody=B>,
54+
S: HttpService<Body, ResBody=B>,
5555
S::Error: Into<Box<dyn StdError + Send + Sync>>,
5656
B: Payload,
5757
B::Data: Unpin,
@@ -89,7 +89,7 @@ where
8989
impl<T, S, B, E> Future for Server<T, S, B, E>
9090
where
9191
T: AsyncRead + AsyncWrite + Unpin,
92-
S: Service<Body, ResBody=B>,
92+
S: HttpService<Body, ResBody=B>,
9393
S::Error: Into<Box<dyn StdError + Send + Sync>>,
9494
B: Payload,
9595
B::Data: Unpin,
@@ -131,7 +131,7 @@ where
131131
{
132132
fn poll_server<S, E>(&mut self, cx: &mut task::Context<'_>, service: &mut S, exec: &mut E) -> Poll<crate::Result<()>>
133133
where
134-
S: Service<
134+
S: HttpService<
135135
Body,
136136
ResBody=B,
137137
>,

Diff for: src/server/conn.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::common::io::Rewind;
2626
use crate::common::{Future, Pin, Poll, Unpin, task};
2727
use crate::error::{Kind, Parse};
2828
use crate::proto;
29-
use crate::service::{MakeServiceRef, Service};
29+
use crate::service::{MakeServiceRef, HttpService};
3030
use crate::upgrade::Upgraded;
3131
use super::Accept;
3232

@@ -117,7 +117,7 @@ pub(super) struct SpawnAll<I, S, E> {
117117
#[pin_project]
118118
pub struct Connection<T, S, E = Exec>
119119
where
120-
S: Service<Body>,
120+
S: HttpService<Body>,
121121
{
122122
pub(super) conn: Option<Either<
123123
proto::h1::Dispatcher<
@@ -356,13 +356,13 @@ impl<E> Http<E> {
356356
///
357357
/// ```
358358
/// # use hyper::{Body, Request, Response};
359-
/// # use hyper::service::Service;
359+
/// # use hyper::service::HttpService;
360360
/// # use hyper::server::conn::Http;
361361
/// # use tokio_io::{AsyncRead, AsyncWrite};
362362
/// # async fn run<I, S>(some_io: I, some_service: S)
363363
/// # where
364364
/// # I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
365-
/// # S: Service<Body, ResBody=Body> + Send + 'static,
365+
/// # S: HttpService<Body, ResBody=Body> + Send + 'static,
366366
/// # S::Future: Send
367367
/// # {
368368
/// let http = Http::new();
@@ -376,7 +376,7 @@ impl<E> Http<E> {
376376
/// ```
377377
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S, E>
378378
where
379-
S: Service<Body, ResBody=Bd>,
379+
S: HttpService<Body, ResBody=Bd>,
380380
S::Error: Into<Box<dyn StdError + Send + Sync>>,
381381
Bd: Payload,
382382
Bd::Data: Unpin,
@@ -431,8 +431,9 @@ impl<E> Http<E> {
431431
ResBody=Bd,
432432
>,
433433
S::Error: Into<Box<dyn StdError + Send + Sync>>,
434+
S::Service: HttpService<Body>,
434435
Bd: Payload,
435-
E: H2Exec<<S::Service as Service<Body>>::Future, Bd>,
436+
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
436437
{
437438
let mut incoming = AddrIncoming::new(addr, None)?;
438439
if self.keep_alive {
@@ -454,7 +455,7 @@ impl<E> Http<E> {
454455
>,
455456
S::Error: Into<Box<dyn StdError + Send + Sync>>,
456457
Bd: Payload,
457-
E: H2Exec<<S::Service as Service<Body>>::Future, Bd>,
458+
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
458459
{
459460
let mut incoming = AddrIncoming::new(addr, Some(handle))?;
460461
if self.keep_alive {
@@ -477,7 +478,7 @@ impl<E> Http<E> {
477478
>,
478479
S::Error: Into<Box<dyn StdError + Send + Sync>>,
479480
Bd: Payload,
480-
E: H2Exec<<S::Service as Service<Body>>::Future, Bd>,
481+
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
481482
{
482483
Serve {
483484
incoming,
@@ -498,7 +499,7 @@ impl<E> Http<E> {
498499
>,
499500
S::Error: Into<Box<dyn StdError + Send + Sync>>,
500501
Bd: Payload,
501-
E: H2Exec<<S::Service as Service<Body>>::Future, Bd>,
502+
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
502503
{
503504
Serve {
504505
incoming,
@@ -513,7 +514,7 @@ impl<E> Http<E> {
513514

514515
impl<I, B, S, E> Connection<I, S, E>
515516
where
516-
S: Service<Body, ResBody=B>,
517+
S: HttpService<Body, ResBody=B>,
517518
S::Error: Into<Box<dyn StdError + Send + Sync>>,
518519
I: AsyncRead + AsyncWrite + Unpin,
519520
B: Payload + 'static,
@@ -662,7 +663,7 @@ where
662663

663664
impl<I, B, S, E> Future for Connection<I, S, E>
664665
where
665-
S: Service<Body, ResBody=B>,
666+
S: HttpService<Body, ResBody=B>,
666667
S::Error: Into<Box<dyn StdError + Send + Sync>>,
667668
I: AsyncRead + AsyncWrite + Unpin + 'static,
668669
B: Payload + 'static,
@@ -700,7 +701,7 @@ where
700701

701702
impl<I, S> fmt::Debug for Connection<I, S>
702703
where
703-
S: Service<Body>,
704+
S: HttpService<Body>,
704705
{
705706
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
706707
f.debug_struct("Connection")
@@ -740,7 +741,7 @@ where
740741
IE: Into<Box<dyn StdError + Send + Sync>>,
741742
S: MakeServiceRef<IO, Body, ResBody=B>,
742743
B: Payload,
743-
E: H2Exec<<S::Service as Service<Body>>::Future, B>,
744+
E: H2Exec<<S::Service as HttpService<Body>>::Future, B>,
744745
{
745746
fn poll_next_(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Option<crate::Result<Connecting<IO, S::Future, E>>>> {
746747
let me = self.project();
@@ -774,7 +775,7 @@ where
774775
IE: Into<Box<dyn StdError + Send + Sync>>,
775776
S: MakeServiceRef<IO, Body, ResBody=B>,
776777
B: Payload,
777-
E: H2Exec<<S::Service as Service<Body>>::Future, B>,
778+
E: H2Exec<<S::Service as HttpService<Body>>::Future, B>,
778779
{
779780
type Item = crate::Result<Connecting<IO, S::Future, E>>;
780781

@@ -790,7 +791,7 @@ impl<I, F, S, FE, E, B> Future for Connecting<I, F, E>
790791
where
791792
I: AsyncRead + AsyncWrite + Unpin,
792793
F: Future<Output=Result<S, FE>>,
793-
S: Service<Body, ResBody=B>,
794+
S: HttpService<Body, ResBody=B>,
794795
B: Payload,
795796
B::Data: Unpin,
796797
E: H2Exec<S::Future, B>,
@@ -831,7 +832,7 @@ where
831832
ResBody=B,
832833
>,
833834
B: Payload,
834-
E: H2Exec<<S::Service as Service<Body>>::Future, B>,
835+
E: H2Exec<<S::Service as HttpService<Body>>::Future, B>,
835836
{
836837
pub(super) fn poll_watch<W>(self: Pin<&mut Self>, cx: &mut task::Context<'_>, watcher: &W) -> Poll<crate::Result<()>>
837838
where
@@ -875,7 +876,7 @@ pub(crate) mod spawn_all {
875876
use crate::body::{Body, Payload};
876877
use crate::common::exec::H2Exec;
877878
use crate::common::{Future, Pin, Poll, Unpin, task};
878-
use crate::service::Service;
879+
use crate::service::HttpService;
879880
use super::{Connecting, UpgradeableConnection};
880881
use pin_project::{pin_project, project};
881882

@@ -887,7 +888,7 @@ pub(crate) mod spawn_all {
887888
// The `Server::with_graceful_shutdown` needs to keep track of all active
888889
// connections, and signal that they start to shutdown when prompted, so
889890
// it has a `GracefulWatcher` implementation to do that.
890-
pub trait Watcher<I, S: Service<Body>, E>: Clone {
891+
pub trait Watcher<I, S: HttpService<Body>, E>: Clone {
891892
type Future: Future<Output = crate::Result<()>>;
892893

893894
fn watch(&self, conn: UpgradeableConnection<I, S, E>) -> Self::Future;
@@ -900,7 +901,7 @@ pub(crate) mod spawn_all {
900901
impl<I, S, E> Watcher<I, S, E> for NoopWatcher
901902
where
902903
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
903-
S: Service<Body> + 'static,
904+
S: HttpService<Body> + 'static,
904905
<S::ResBody as Payload>::Data: Unpin,
905906
E: H2Exec<S::Future, S::ResBody>,
906907
{
@@ -923,18 +924,18 @@ pub(crate) mod spawn_all {
923924

924925
#[pin_project]
925926
#[allow(missing_debug_implementations)]
926-
pub struct NewSvcTask<I, N, S: Service<Body>, E, W: Watcher<I, S, E>> {
927+
pub struct NewSvcTask<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> {
927928
#[pin]
928929
state: State<I, N, S, E, W>,
929930
}
930931

931932
#[pin_project]
932-
pub enum State<I, N, S: Service<Body>, E, W: Watcher<I, S, E>> {
933+
pub enum State<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> {
933934
Connecting(#[pin] Connecting<I, N, E>, W),
934935
Connected(#[pin] W::Future),
935936
}
936937

937-
impl<I, N, S: Service<Body>, E, W: Watcher<I, S, E>> NewSvcTask<I, N, S, E, W> {
938+
impl<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> NewSvcTask<I, N, S, E, W> {
938939
pub(super) fn new(connecting: Connecting<I, N, E>, watcher: W) -> Self {
939940
NewSvcTask {
940941
state: State::Connecting(connecting, watcher),
@@ -947,7 +948,7 @@ pub(crate) mod spawn_all {
947948
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
948949
N: Future<Output=Result<S, NE>>,
949950
NE: Into<Box<dyn StdError + Send + Sync>>,
950-
S: Service<Body, ResBody=B>,
951+
S: HttpService<Body, ResBody=B>,
951952
B: Payload,
952953
B::Data: Unpin,
953954
E: H2Exec<S::Future, B>,
@@ -1008,14 +1009,14 @@ mod upgrades {
10081009
#[allow(missing_debug_implementations)]
10091010
pub struct UpgradeableConnection<T, S, E>
10101011
where
1011-
S: Service<Body>,
1012+
S: HttpService<Body>,
10121013
{
10131014
pub(super) inner: Connection<T, S, E>,
10141015
}
10151016

10161017
impl<I, B, S, E> UpgradeableConnection<I, S, E>
10171018
where
1018-
S: Service<Body, ResBody=B>,// + 'static,
1019+
S: HttpService<Body, ResBody=B>,// + 'static,
10191020
S::Error: Into<Box<dyn StdError + Send + Sync>>,
10201021
I: AsyncRead + AsyncWrite + Unpin,
10211022
B: Payload + 'static,
@@ -1033,7 +1034,7 @@ mod upgrades {
10331034

10341035
impl<I, B, S, E> Future for UpgradeableConnection<I, S, E>
10351036
where
1036-
S: Service<Body, ResBody=B> + 'static,
1037+
S: HttpService<Body, ResBody=B> + 'static,
10371038
S::Error: Into<Box<dyn StdError + Send + Sync>>,
10381039
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
10391040
B: Payload + 'static,

0 commit comments

Comments
 (0)