pub trait UnixListenerExt {
// Required method
fn serve<MakeResponseFn, ResponseFn, ResponseFuture, B, E>(
self,
f: MakeResponseFn,
) -> impl Future<Output = Result<(), Box<dyn Error + Send + Sync>>>
where MakeResponseFn: Fn() -> ResponseFn,
ResponseFn: Fn(Request<Incoming>) -> ResponseFuture,
ResponseFuture: Future<Output = Result<Response<B>, E>>,
B: Body + 'static,
<B as Body>::Error: Error + Send + Sync,
E: Error + Send + Sync + 'static;
}
Expand description
Extension trait for provisioning a hyper HTTP server over a Unix domain socket.
§Example
use hyper::Response;
use hyperlocal::UnixListenerExt;
use tokio::net::UnixListener;
let future = async move {
let listener = UnixListener::bind("/tmp/hyperlocal.sock").expect("parsed unix path");
listener
.serve(|| {
|_request| async {
Ok::<_, hyper::Error>(Response::new("Hello, world.".to_string()))
}
})
.await
.expect("failed to serve a connection")
};
Required Methods§
sourcefn serve<MakeResponseFn, ResponseFn, ResponseFuture, B, E>(
self,
f: MakeResponseFn,
) -> impl Future<Output = Result<(), Box<dyn Error + Send + Sync>>>
fn serve<MakeResponseFn, ResponseFn, ResponseFuture, B, E>( self, f: MakeResponseFn, ) -> impl Future<Output = Result<(), Box<dyn Error + Send + Sync>>>
Indefinitely accept and respond to connections.
Pass a function which will generate the function which responds to all requests for an individual connection.
Object Safety§
This trait is not object safe.