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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.