pub struct BoxCloneService<T, U, E>(/* private fields */);
Available on crate feature
util
only.Expand description
BoxCloneService
turns a service into a trait object, allowing the
response future type to be dynamic, and allowing the service to be cloned.
This is similar to BoxService
except the resulting
service implements Clone
.
§Example
use tower::{Service, ServiceBuilder, BoxError, util::BoxCloneService};
use std::time::Duration;
// This service has a complex type that is hard to name
let service = ServiceBuilder::new()
.map_request(|req| {
println!("received request");
req
})
.map_response(|res| {
println!("response produced");
res
})
.load_shed()
.concurrency_limit(64)
.timeout(Duration::from_secs(10))
.service_fn(|req: Request| async {
Ok::<_, BoxError>(Response::new())
});
// `BoxCloneService` will erase the type so it's nameable
let service: BoxCloneService<Request, Response, BoxError> = BoxCloneService::new(service);
// And we can still clone the service
let cloned_service = service.clone();
Implementations§
Source§impl<T, U, E> BoxCloneService<T, U, E>
impl<T, U, E> BoxCloneService<T, U, E>
Trait Implementations§
Source§impl<T, U, E> Clone for BoxCloneService<T, U, E>
impl<T, U, E> Clone for BoxCloneService<T, U, E>
Source§impl<T, U, E> Debug for BoxCloneService<T, U, E>
impl<T, U, E> Debug for BoxCloneService<T, U, E>
Auto Trait Implementations§
impl<T, U, E> Freeze for BoxCloneService<T, U, E>
impl<T, U, E> !RefUnwindSafe for BoxCloneService<T, U, E>
impl<T, U, E> Send for BoxCloneService<T, U, E>
impl<T, U, E> !Sync for BoxCloneService<T, U, E>
impl<T, U, E> Unpin for BoxCloneService<T, U, E>
impl<T, U, E> !UnwindSafe for BoxCloneService<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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,
Available on crate feature
util
only.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,
Available on crate feature
util
only.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,
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.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>
Available on crate feature
util
only.Composes a function that transforms futures produced by the service. Read more
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes