Struct Builder

Source
pub struct Builder<I: TryStream, Sp> { /* private fields */ }
Expand description

A builder for a Server.

Implementations§

Source§

impl<I: TryStream, Sp> Builder<I, Sp>

Source

pub fn with_spawner<Sp2>(self, new_spawner: Sp2) -> Builder<I, Sp2>

Sets the Spawn to deal with starting connection tasks.

Source

pub fn serve<S: HttpService>(self, service: S) -> Server<I, S, Sp>
where I: TryStream + Unpin, I::Ok: AsyncRead + AsyncWrite + Send + Unpin + 'static, I::Error: Into<Box<dyn Error + Send + Sync>>, Sp: Clone + Send + 'static, for<'a> &'a Sp: Spawn,

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§

Source§

impl<I: TryStream, Sp> Debug for Builder<I, Sp>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I, Sp> Freeze for Builder<I, Sp>
where Sp: Freeze, I: Freeze,

§

impl<I, Sp> RefUnwindSafe for Builder<I, Sp>

§

impl<I, Sp> Send for Builder<I, Sp>
where Sp: Send, I: Send,

§

impl<I, Sp> Sync for Builder<I, Sp>
where Sp: Sync, I: Sync,

§

impl<I, Sp> Unpin for Builder<I, Sp>
where Sp: Unpin, I: Unpin,

§

impl<I, Sp> UnwindSafe for Builder<I, Sp>
where Sp: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.