server_from_handler

Function server_from_handler 

Source
pub fn server_from_handler<H, Tr, S>(
    handler: H,
) -> impl ServerBuilder<Tr> + Clone + Send
where Tr: Fragment, Tr::Resource: SpiritAccept + Unpin, <Tr::Resource as SpiritAccept>::Connection: AsyncRead + AsyncWrite + Unpin, H: Clone + Send + Sync + Fn(Request<Body>) -> S + 'static, S: Future<Output = Response<Body>> + Send + 'static,
Expand description

A simplified version of creating the ServerBuilder.

Implementing the ServerBuilder by hand is possible and sometimes necessary (it is more flexible ‒ one can receive parameters on the way ‒ the configuration of the specific server instance in case there are multiple, getting access to the connection for which a service is being created, unusual ways of creating the instances). But it is quite a chore with a lot of async and move involved (you can have a look at source code of this function to get the idea, the [SRC] button at the right).

This gets it done for the very simple case ‒ in case there’s an async function/closure that just takes a Request<Body> and returns a Response<Body>.

See the crate level example.