diff --git a/Cargo.toml b/Cargo.toml index 4d750d6630..90380e9fae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ net2 = "0.2.32" time = "0.1" tokio = "0.1.5" tokio-executor = "0.1.0" -tokio-service = "0.1" tokio-io = "0.1" want = "0.0.3" diff --git a/examples/hello.rs b/examples/hello.rs index f3c476cd91..302f7bdc2a 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -6,8 +6,8 @@ extern crate tokio; use futures::Future; -use hyper::{Body, Response}; -use hyper::server::{Server, const_service, service_fn}; +use hyper::{Body, Response, Server}; +use hyper::service::service_fn_ok; static PHRASE: &'static [u8] = b"Hello World!"; @@ -16,10 +16,16 @@ fn main() { let addr = ([127, 0, 0, 1], 3000).into(); - let new_service = const_service(service_fn(|_| { - //TODO: when `!` is stable, replace error type - Ok::<_, hyper::Error>(Response::new(Body::from(PHRASE))) - })); + // new_service is run for each connection, creating a 'service' + // to handle requests for that specific connection. + let new_service = || { + // This is the `Service` that will handle the connection. + // `service_fn_ok` is a helper to convert a function that + // returns a Response into a `Service`. + service_fn_ok(|_| { + Response::new(Body::from(PHRASE)) + }) + }; let server = Server::bind(&addr) .serve(new_service) diff --git a/examples/multi_server.rs b/examples/multi_server.rs index f8989fa334..3988561cac 100644 --- a/examples/multi_server.rs +++ b/examples/multi_server.rs @@ -5,39 +5,14 @@ extern crate pretty_env_logger; extern crate tokio; use futures::{Future}; -use futures::future::{FutureResult, lazy}; +use futures::future::{lazy}; -use hyper::{Body, Method, Request, Response, StatusCode}; -use hyper::server::{Server, Service}; +use hyper::{Body, Response, Server}; +use hyper::service::service_fn_ok; static INDEX1: &'static [u8] = b"The 1st service!"; static INDEX2: &'static [u8] = b"The 2nd service!"; -struct Srv(&'static [u8]); - -impl Service for Srv { - type Request = Request
; - type Response = Response; - type Error = hyper::Error; - type Future = FutureResult