Struct tower::make::Shared [−][src]
pub struct Shared<S> { /* fields omitted */ }
make
only.Expand description
A MakeService
that produces services by cloning an inner service.
Example
use tower::make::{MakeService, Shared};
use tower::buffer::Buffer;
use tower::Service;
use futures::future::{Ready, ready};
// An example connection type
struct Connection {}
// An example request type
struct Request {}
// An example response type
struct Response {}
// Some service that doesn't implement `Clone`
struct MyService;
impl Service<Request> for MyService {
type Response = Response;
type Error = Infallible;
type Future = Ready<Result<Response, Infallible>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Request) -> Self::Future {
ready(Ok(Response {}))
}
}
// Example function that runs a service by accepting new connections and using
// `Make` to create new services that might be bound to the connection.
//
// This is similar to what you might find in hyper.
async fn serve_make_service<Make>(make: Make)
where
Make: MakeService<Connection, Request>
{
// ...
}
// Our service
let svc = MyService;
// Make it `Clone` by putting a channel in front
let buffered = Buffer::new(svc, 1024);
// Convert it into a `MakeService`
let make = Shared::new(buffered);
// Run the service and just ignore the `Connection`s as `MyService` doesn't need them
serve_make_service(make).await;
Implementations
Trait Implementations
type Response = S
type Response = S
Responses given by the service.
type Error = Infallible
type Error = Infallible
Errors produced by the service.
type Future = SharedFuture<S>
type Future = SharedFuture<S>
The future response value.
Returns Poll::Ready(Ok(()))
when the service is able to process requests. Read more
Auto Trait Implementations
impl<S> RefUnwindSafe for Shared<S> where
S: RefUnwindSafe,
impl<S> UnwindSafe for Shared<S> where
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
util
only.Yields a mutable reference to the service when it is ready to accept a request.
please use the ServiceExt::ready
method instead
util
only.Yields a mutable reference to the service when it is ready to accept a request.
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,
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,
impl<T, Request> Future for ReadyOneshot<T, Request> where
T: Service<Request>, type Output = Result<T, T::Error>;
util
only.Yields the service when it is ready to accept a request.
util
only.Consume this Service
, calling with the providing request once it is ready.
util
only.util
only.Executes a new future after this service’s future resolves. This does
not alter the behaviour of the poll_ready
method. Read more
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F> where
Self: Sized,
F: FnOnce(Self::Response) -> Response + Clone,
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F> where
Self: Sized,
F: FnOnce(Self::Response) -> Response + Clone,
util
only.Maps this service’s response value to a different value. This does not
alter the behaviour of the poll_ready
method. Read more
util
only.Maps this service’s error value to a different value. This does not
alter the behaviour of the poll_ready
method. Read more
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 more
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F> where
Self: Sized,
F: FnMut(NewRequest) -> Request,
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F> where
Self: Sized,
F: FnMut(NewRequest) -> Request,
util
only.Composes a function in front of the service. Read more
util
and filter
only.fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F> where
Self: Sized,
F: AsyncPredicate<NewRequest>,
fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F> where
Self: Sized,
F: AsyncPredicate<NewRequest>,
util
and filter
only.Composes this service with an AsyncFilter
that conditionally accepts or
rejects requests based on an [async predicate]. Read more
util
only.Composes an asynchronous function after this service. Read more
util
only.Composes a function that transforms futures produced by the service. Read more
util
only.pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more