[][src]Struct http_service_h1::Server

pub struct Server<I, S: HttpService> { /* fields omitted */ }

A listening HTTP server that accepts connections in HTTP1.

Methods

impl<I: Stream<Item = Result<TcpStream>>, S: HttpService> Server<I, S> where
    <<S as HttpService>::ResponseFuture as Future>::Output: Send,
    <S as HttpService>::Connection: Sync,
    I: Unpin + Send + Sync
[src]

pub fn new(addr: String, incoming: I, service: S) -> Self[src]

Consume this [Builder], creating a Server.

Examples

use http_service::{Response, Body};
use http_service_h1::Server;
use async_std::net::TcpListener;

// And an HttpService to handle each connection...
let service = |req| async {
    Ok::<Response, async_std::io::Error>(Response::from("Hello World"))
};

async_std::task::block_on(async move {
    // Then bind, configure the spawner to our pool, and serve...
    let mut listener = TcpListener::bind("127.0.0.1:3000").await?;
    let addr = format!("http://{}", listener.local_addr()?);
    let mut server = Server::new(addr, listener.incoming(), service);
    server.run().await?;
    Ok::<(), Box<dyn std::error::Error>>(())
})?;

pub async fn run<'_>(&'_ mut self) -> Result<()>[src]

Run the server forever-ish.

Trait Implementations

impl<I: Debug, S: Debug + HttpService> Debug for Server<I, S>[src]

Auto Trait Implementations

impl<I, S> RefUnwindSafe for Server<I, S> where
    I: RefUnwindSafe,
    S: RefUnwindSafe

impl<I, S> Send for Server<I, S> where
    I: Send

impl<I, S> Sync for Server<I, S> where
    I: Sync

impl<I, S> Unpin for Server<I, S> where
    I: Unpin

impl<I, S> UnwindSafe for Server<I, S> where
    I: UnwindSafe,
    S: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.