Skip to content

Commit

Permalink
feat(service): rename Service to HttpService, re-export tower::Se…
Browse files Browse the repository at this point in the history
…rvice`

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
  • Loading branch information
seanmonstar committed Oct 19, 2019
1 parent ca5836f commit 770e51c
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 271 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ log = "0.4"
pin-project = "0.4"
time = "0.1"
tower-service = "=0.3.0-alpha.2"
tower-make = { version = "=0.3.0-alpha.2a", features = ['io'] }
tokio-executor = "=0.2.0-alpha.6"
tokio-io = "=0.2.0-alpha.6"
tokio-sync = "=0.2.0-alpha.6"
Expand Down
6 changes: 4 additions & 2 deletions examples/tower_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![deny(warnings)]

use hyper::client::service::{Connect, Service, MakeService};
use hyper::client::service::Connect;
use hyper::client::conn::Builder;
use hyper::client::connect::HttpConnector;
use hyper::service::Service;
use hyper::{Body, Request};

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


let mut svc = mk_svc.make_service(uri.clone()).await?;
let mut svc = mk_svc.call(uri.clone()).await?;

let body = Body::empty();

Expand Down
7 changes: 4 additions & 3 deletions examples/tower_server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![deny(warnings)]

use hyper::{Body, Request, Response, Server};
use tower_service::Service;
use futures_util::future;
use std::task::{Context, Poll};

use futures_util::future;
use hyper::{Body, Request, Response, Server};
use hyper::service::Service;

const ROOT: &'static str = "/";

#[derive(Debug)]
Expand Down
10 changes: 3 additions & 7 deletions src/client/service.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
//! Utilities used to interact with the Tower ecosystem.
//!
//! This module provides exports of `Service`, `MakeService` and `Connect` which
//! all provide hook-ins into the Tower ecosystem.
//! This module provides `Connect` which hook-ins into the Tower ecosystem.
use super::conn::{SendRequest, Builder};
use std::marker::PhantomData;
use crate::{common::{Poll, task, Pin}, body::Payload};
use std::future::Future;
use std::error::Error as StdError;
use tower_make::MakeConnection;

pub use tower_service::Service;
pub use tower_make::MakeService;
use crate::{common::{Poll, task, Pin}, body::Payload, service::{MakeConnection, Service}};
use super::conn::{SendRequest, Builder};

/// Creates a connection via `SendRequest`.
///
Expand Down
8 changes: 4 additions & 4 deletions src/common/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use tokio_executor::{SpawnError, TypedExecutor};
use crate::body::{Payload, Body};
use crate::proto::h2::server::H2Stream;
use crate::server::conn::spawn_all::{NewSvcTask, Watcher};
use crate::service::Service;
use crate::service::HttpService;

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

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

Expand Down Expand Up @@ -119,7 +119,7 @@ where
impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for Exec
where
NewSvcTask<I, N, S, E, W>: Future<Output=()> + Send + 'static,
S: Service<Body>,
S: HttpService<Body>,
W: Watcher<I, S, E>,
{
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()> {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for E
where
E: TypedExecutor<NewSvcTask<I, N, S, E, W>> + Clone,
NewSvcTask<I, N, S, E, W>: Future<Output=()>,
S: Service<Body>,
S: HttpService<Body>,
W: Watcher<I, S, E>,
{
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>) -> crate::Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::body::{Body, Payload};
use crate::common::{Future, Never, Poll, Pin, Unpin, task};
use crate::proto::{BodyLength, DecodedLength, Conn, Dispatched, MessageHead, RequestHead, RequestLine, ResponseHead};
use super::Http1Transaction;
use crate::service::Service;
use crate::service::HttpService;

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

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

impl<S, B> Server<S, B>
where
S: Service<B>,
S: HttpService<B>,
{
pub fn new(service: S) -> Server<S, B> {
Server {
Expand All @@ -422,11 +422,11 @@ where
}

// Service is never pinned
impl<S: Service<B>, B> Unpin for Server<S, B> {}
impl<S: HttpService<B>, B> Unpin for Server<S, B> {}

impl<S, Bs> Dispatch for Server<S, Body>
where
S: Service<Body, ResBody=Bs>,
S: HttpService<Body, ResBody=Bs>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bs: Payload,
{
Expand Down
12 changes: 6 additions & 6 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use crate::common::exec::H2Exec;
use crate::common::{Future, Pin, Poll, task};
use crate::headers;
use crate::headers::content_length_parse_all;
use crate::service::Service;
use crate::service::HttpService;
use crate::proto::Dispatched;
use super::{PipeToSendStream, SendBuf};

use crate::{Body, Response};

pub(crate) struct Server<T, S, B, E>
where
S: Service<Body>,
S: HttpService<Body>,
B: Payload,
{
exec: E,
Expand All @@ -28,7 +28,7 @@ where
}

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

enum State<T, B>
where
Expand All @@ -51,7 +51,7 @@ where
impl<T, S, B, E> Server<T, S, B, E>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Body, ResBody=B>,
S: HttpService<Body, ResBody=B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B::Data: Unpin,
Expand Down Expand Up @@ -89,7 +89,7 @@ where
impl<T, S, B, E> Future for Server<T, S, B, E>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Body, ResBody=B>,
S: HttpService<Body, ResBody=B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B::Data: Unpin,
Expand Down Expand Up @@ -131,7 +131,7 @@ where
{
fn poll_server<S, E>(&mut self, cx: &mut task::Context<'_>, service: &mut S, exec: &mut E) -> Poll<crate::Result<()>>
where
S: Service<
S: HttpService<
Body,
ResBody=B,
>,
Expand Down
Loading

0 comments on commit 770e51c

Please sign in to comment.