hyper::server::accept

Function poll_fn

Source
pub fn poll_fn<F, IO, E>(func: F) -> impl Accept<Conn = IO, Error = E>
where F: FnMut(&mut Context<'_>) -> Poll<Option<Result<IO, E>>>,
Expand description

Create an Accept with a polling function.

ยงExample

use std::task::Poll;
use hyper::server::{accept, Server};

// If we created some mocked connection...
let mut conn = Some(mock_conn);

// And accept just the mocked conn once...
let once = accept::poll_fn(move |cx| {
    Poll::Ready(conn.take().map(Ok::<_, ()>))
});

let builder = Server::builder(once);