Skip to content

Commit 4f27439

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 4f27439

15 files changed

+260
-271
lines changed

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"

examples/tower_client.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![deny(warnings)]
12

2-
use hyper::client::service::{Connect, Service, MakeService};
3+
use hyper::client::service::Connect;
34
use hyper::client::conn::Builder;
45
use hyper::client::connect::HttpConnector;
6+
use hyper::service::Service;
57
use hyper::{Body, Request};
68

79
#[tokio::main]
@@ -13,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1315
let uri = "http://127.0.0.1:8080".parse::<http::Uri>()?;
1416

1517

16-
let mut svc = mk_svc.make_service(uri.clone()).await?;
18+
let mut svc = mk_svc.call(uri.clone()).await?;
1719

1820
let body = Body::empty();
1921

examples/tower_server.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![deny(warnings)]
22

3-
use hyper::{Body, Request, Response, Server};
4-
use tower_service::Service;
5-
use futures_util::future;
63
use std::task::{Context, Poll};
74

5+
use futures_util::future;
6+
use hyper::{Body, Request, Response, Server};
7+
use hyper::service::Service;
8+
89
const ROOT: &'static str = "/";
910

1011
#[derive(Debug)]

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
///

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<()> {

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
{

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
>,

0 commit comments

Comments
 (0)