Function future_service
fn future_service<F, S, R, E>(future: F) -> FutureService<F, S>
where
F: Future<Output = Result<S, E>> + Unpin,
S: Service<R, Error = E>
Returns a new FutureService for the given future.
A FutureService allows you to treat a future that resolves to a service as a service. This
can be useful for services that are created asynchronously.
Example
use ;
use future_service;
use Infallible;
#
Regarding the Unpin bound
The Unpin bound on F is necessary because the future will be polled in
Service::poll_ready which doesn't have a pinned receiver (it takes &mut self and not self: Pin<&mut Self>). So we cannot put the future into a Pin without requiring Unpin.
This will most likely come up if you're calling future_service with an async block. In that
case you can use Box::pin(async { ... }) as shown in the example.