Skip to content

Commit 6d5bb85

Browse files
committed
docs(server): add example to serve_connection
1 parent e6647aa commit 6d5bb85

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/server/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,34 @@ impl<B: AsRef<[u8]> + 'static> Http<B> {
257257
///
258258
/// This returns a Future that must be polled in order for HTTP to be
259259
/// driven on the connection.
260+
///
261+
/// # Example
262+
///
263+
/// ```
264+
/// # extern crate futures;
265+
/// # extern crate hyper;
266+
/// # extern crate tokio_core;
267+
/// # extern crate tokio_io;
268+
/// # use futures::Future;
269+
/// # use hyper::server::{Http, Request, Response, Service};
270+
/// # use tokio_io::{AsyncRead, AsyncWrite};
271+
/// # use tokio_core::reactor::Handle;
272+
/// # fn run<I, S>(some_io: I, some_service: S, some_handle: &Handle)
273+
/// # where
274+
/// # I: AsyncRead + AsyncWrite + 'static,
275+
/// # S: Service<Request=Request, Response=Response, Error=hyper::Error> + 'static,
276+
/// # {
277+
/// let http = Http::<hyper::Chunk>::new();
278+
/// let conn = http.serve_connection(some_io, some_service);
279+
///
280+
/// let fut = conn
281+
/// .map(|_| ())
282+
/// .map_err(|e| eprintln!("server connection error: {}", e));
283+
///
284+
/// some_handle.spawn(fut);
285+
/// # }
286+
/// # fn main() {}
287+
/// ```
260288
pub fn serve_connection<S, I, Bd>(&self, io: I, service: S) -> Connection<I, S>
261289
where S: Service<Request = Request, Response = Response<Bd>, Error = ::Error>,
262290
Bd: Stream<Error=::Error>,

0 commit comments

Comments
 (0)