[−][src]Function rweb::service
pub fn service<F>(filter: F) -> FilteredService<F> where
F: Filter,
<<F as FilterBase>::Future as TryFuture>::Ok: Reply,
<<F as FilterBase>::Future as TryFuture>::Error: IsReject,
Convert a Filter
into a Service
.
Filters are normally what APIs are built on in warp. However, it can be
useful to convert a Filter
into a Service
, such as if
further customizing a hyper::Service
, or if wanting to make use of
the greater Tower set of middleware.
Example
Running a warp::Filter
on a regular hyper::Server
:
use std::convert::Infallible; use warp::Filter; // Our Filter... let route = warp::any().map(|| "Hello From Warp!"); // Convert it into a `Service`... let svc = warp::service(route); // Typical hyper setup... let make_svc = hyper::service::make_service_fn(move |_| async move { Ok::<_, Infallible>(svc) }); hyper::Server::bind(&([127, 0, 0, 1], 3030).into()) .serve(make_svc) .await?;