Skip to content
This repository was archived by the owner on Jun 21, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions http-service-hyper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ where
}
}

/// Serve the given `HttpService` at the given address, using `hyper` as backend.
pub fn serve<S: HttpService>(s: S, addr: SocketAddr) {
/// Serve the given `HttpService` at the given address, using `hyper` as backend, and return a
/// `Future` that can be `await`ed on.
pub fn serve<S: HttpService>(
s: S,
addr: SocketAddr,
) -> impl Future<Output = Result<(), hyper::Error>> {
let service = WrapHttpService {
service: Arc::new(s),
};
let server = hyper::Server::bind(&addr)
.serve(service)
.compat()
.map(|_| {
let res: Result<(), ()> = Ok(());
res
})
.compat();
hyper::Server::bind(&addr).serve(service).compat()
}

/// Run the given `HttpService` at the given address on the default runtime, using `hyper` as
/// backend.
pub fn run<S: HttpService>(s: S, addr: SocketAddr) {
let server = serve(s, addr).map(|_| Result::<_, ()>::Ok(())).compat();
hyper::rt::run(server);
}