[−][src]Struct tower::util::FutureService
A type that implements Service
for a Future
that produces a Service
.
See future_service
for more details.
Implementations
impl<F, S> FutureService<F, S>
[src]
pub fn new(future: F) -> Self
[src]
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 tower::{service_fn, Service, ServiceExt}; use tower::util::FutureService; use std::convert::Infallible; // A future which outputs a type implementing `Service`. let future_of_a_service = async { let svc = service_fn(|_req: ()| async { Ok::<_, Infallible>("ok") }); Ok::<_, Infallible>(svc) }; // Wrap the future with a `FutureService`, allowing it to be used // as a service without awaiting the future's completion: let mut svc = FutureService::new(Box::pin(future_of_a_service)); // Now, when we wait for the service to become ready, it will // drive the future to completion internally. let svc = svc.ready_and().await.unwrap(); let res = svc.call(()).await.unwrap();
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.
Trait Implementations
impl<F: Clone, S: Clone> Clone for FutureService<F, S>
[src]
fn clone(&self) -> FutureService<F, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<F, S> Debug for FutureService<F, S> where
S: Debug,
[src]
S: Debug,
impl<F, S, R, E> Service<R> for FutureService<F, S> where
F: Future<Output = Result<S, E>> + Unpin,
S: Service<R, Error = E>,
[src]
F: Future<Output = Result<S, E>> + Unpin,
S: Service<R, Error = E>,
Auto Trait Implementations
impl<F, S> RefUnwindSafe for FutureService<F, S> where
F: RefUnwindSafe,
S: RefUnwindSafe,
F: RefUnwindSafe,
S: RefUnwindSafe,
impl<F, S> Send for FutureService<F, S> where
F: Send,
S: Send,
F: Send,
S: Send,
impl<F, S> Sync for FutureService<F, S> where
F: Sync,
S: Sync,
F: Sync,
S: Sync,
impl<F, S> Unpin for FutureService<F, S> where
F: Unpin,
S: Unpin,
F: Unpin,
S: Unpin,
impl<F, S> UnwindSafe for FutureService<F, S> where
F: UnwindSafe,
S: UnwindSafe,
F: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, Request> ServiceExt<Request> for T where
T: Service<Request> + ?Sized,
[src]
T: Service<Request> + ?Sized,
fn ready_and(&mut self) -> ReadyAnd<'_, Self, Request>ⓘ where
Self: Sized,
[src]
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>ⓘNotable traits for ReadyOneshot<T, Request>
impl<T, Request> Future for ReadyOneshot<T, Request> where
T: Service<Request>, type Output = Result<T, T::Error>;
where
Self: Sized,
[src]
Notable traits for ReadyOneshot<T, Request>
impl<T, Request> Future for ReadyOneshot<T, Request> where
T: Service<Request>, type Output = Result<T, T::Error>;
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>ⓘ where
Self: Sized,
[src]
Self: Sized,
fn call_all<S>(self, reqs: S) -> CallAll<Self, S> where
Self: Sized,
Self::Error: Into<BoxError>,
S: Stream<Item = Request>,
[src]
Self: Sized,
Self::Error: Into<BoxError>,
S: Stream<Item = Request>,
fn and_then<F>(self, f: F) -> AndThen<Self, F> where
Self: Sized,
F: Clone,
[src]
Self: Sized,
F: Clone,
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F> where
Self: Sized,
F: FnOnce(Self::Response) -> Response + Clone,
[src]
Self: Sized,
F: FnOnce(Self::Response) -> Response + Clone,
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F> where
Self: Sized,
F: FnOnce(Self::Error) -> Error + Clone,
[src]
Self: Sized,
F: FnOnce(Self::Error) -> Error + Clone,
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F> where
Self: Sized,
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
[src]
Self: Sized,
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F> where
Self: Sized,
F: FnMut(NewRequest) -> Request + Clone,
[src]
Self: Sized,
F: FnMut(NewRequest) -> Request + Clone,
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F> where
Self: Sized,
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone,
Fut: Future<Output = Result<Response, Error>>,
[src]
Self: Sized,
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone,
Fut: Future<Output = Result<Response, Error>>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,