pub struct Builder<I: TryStream, Sp> { /* private fields */ }
Expand description
A builder for a Server
.
Implementations§
Source§impl<I: TryStream, Sp> Builder<I, Sp>
impl<I: TryStream, Sp> Builder<I, Sp>
Sourcepub fn with_spawner<Sp2>(self, new_spawner: Sp2) -> Builder<I, Sp2>
pub fn with_spawner<Sp2>(self, new_spawner: Sp2) -> Builder<I, Sp2>
Sets the Spawn
to deal with starting connection tasks.
Sourcepub fn serve<S: HttpService>(self, service: S) -> Server<I, S, Sp> ⓘ
pub fn serve<S: HttpService>(self, service: S) -> Server<I, S, Sp> ⓘ
Consume this Builder
, creating a Server
.
§Examples
use http_service::{Response, Body};
use http_service_hyper::Server;
use romio::TcpListener;
// Construct an executor to run our tasks on
let mut pool = futures::executor::ThreadPool::new()?;
// And an HttpService to handle each connection...
let service = |req| {
futures::future::ok::<_, ()>(Response::new(Body::from("Hello World")))
};
// Then bind, configure the spawner to our pool, and serve...
let addr = "127.0.0.1:3000".parse()?;
let mut listener = TcpListener::bind(&addr)?;
let server = Server::builder(listener.incoming())
.with_spawner(pool.clone())
.serve(service);
// Finally, spawn `server` onto our executor...
pool.run(server)?;
Trait Implementations§
Auto Trait Implementations§
impl<I, Sp> Freeze for Builder<I, Sp>
impl<I, Sp> RefUnwindSafe for Builder<I, Sp>where
Sp: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, Sp> Send for Builder<I, Sp>
impl<I, Sp> Sync for Builder<I, Sp>
impl<I, Sp> Unpin for Builder<I, Sp>
impl<I, Sp> UnwindSafe for Builder<I, Sp>where
Sp: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more