Struct tower::util::BoxService
source · pub struct BoxService<T, U, E> { /* private fields */ }
Expand description
A boxed Service + Send
trait object.
BoxService
turns a service into a trait object, allowing the response
future type to be dynamic. This type requires both the service and the
response future to be Send
.
If you need a boxed Service
that implements Clone
consider using
BoxCloneService
.
Dynamically dispatched Service
objects allow for erasing the underlying
Service
type and using the Service
instances as opaque handles. This can
be useful when the service instance cannot be explicitly named for whatever
reason.
§Examples
use futures_util::future::ready;
// Respond to requests using a closure, but closures cannot be named...
let svc = service_fn(|mut request: String| {
request.push_str(" response");
ready(Ok(request))
});
let service: BoxService<String, String, ()> = BoxService::new(svc);
}
Implementations§
source§impl<T, U, E> BoxService<T, U, E>
impl<T, U, E> BoxService<T, U, E>
Trait Implementations§
source§impl<T, U, E> Debug for BoxService<T, U, E>
impl<T, U, E> Debug for BoxService<T, U, E>
Auto Trait Implementations§
impl<T, U, E> Freeze for BoxService<T, U, E>
impl<T, U, E> !RefUnwindSafe for BoxService<T, U, E>
impl<T, U, E> Send for BoxService<T, U, E>
impl<T, U, E> Sync for BoxService<T, U, E>
impl<T, U, E> Unpin for BoxService<T, U, E>
impl<T, U, E> !UnwindSafe for BoxService<T, U, E>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
source§fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
Yields a mutable reference to the service when it is ready to accept a request.
source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
Yields the service when it is ready to accept a request.
source§fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
Consume this
Service
, calling it with the provided request once it is ready.source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
Executes a new future after this service’s future resolves. This does
not alter the behaviour of the
poll_ready
method. Read moresource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
Maps this service’s response value to a different value. This does not
alter the behaviour of the
poll_ready
method. Read moresource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
Maps this service’s error value to a different value. This does not
alter the behaviour of the
poll_ready
method. Read moresource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Maps this service’s result type (
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read moresource§fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
Composes a function in front of the service. Read more
source§fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
Composes an asynchronous function after this service. Read more
source§fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
Composes a function that transforms futures produced by the service. Read more