pub struct Buffer<T, Request>where
T: Service<Request>,{ /* private fields */ }
Expand description
Adds an mpsc buffer in front of an inner service.
See the module documentation for more details.
Implementations
sourceimpl<T, Request> Buffer<T, Request>where
T: Service<Request>,
T::Error: Into<BoxError>,
impl<T, Request> Buffer<T, Request>where
T: Service<Request>,
T::Error: Into<BoxError>,
sourcepub fn new(service: T, bound: usize) -> Selfwhere
T: Send + 'static,
T::Future: Send,
T::Error: Send + Sync,
Request: Send + 'static,
pub fn new(service: T, bound: usize) -> Selfwhere
T: Send + 'static,
T::Future: Send,
T::Error: Send + Sync,
Request: Send + 'static,
Creates a new Buffer
wrapping service
.
bound
gives the maximal number of requests that can be queued for the service before
backpressure is applied to callers.
The default Tokio executor is used to run the given service, which means that this method must be called while on the Tokio runtime.
A note on choosing a bound
When Buffer
’s implementation of poll_ready
returns Poll::Ready
, it reserves a
slot in the channel for the forthcoming call
. However, if this call doesn’t arrive,
this reserved slot may be held up for a long time. As a result, it’s advisable to set
bound
to be at least the maximum number of concurrent requests the Buffer
will see.
If you do not, all the slots in the buffer may be held up by futures that have just called
poll_ready
but will not issue a call
, which prevents other senders from issuing new
requests.
Trait Implementations
sourceimpl<T, Request> Clone for Buffer<T, Request>where
T: Service<Request>,
impl<T, Request> Clone for Buffer<T, Request>where
T: Service<Request>,
1.0.0const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T: Debug, Request: Debug> Debug for Buffer<T, Request>where
T: Service<Request>,
T::Future: Debug,
impl<T: Debug, Request: Debug> Debug for Buffer<T, Request>where
T: Service<Request>,
T::Future: Debug,
sourceimpl<T, Request> Service<Request> for Buffer<T, Request>where
T: Service<Request>,
T::Error: Into<BoxError>,
impl<T, Request> Service<Request> for Buffer<T, Request>where
T: Service<Request>,
T::Error: Into<BoxError>,
type Error = Box<dyn Error + Sync + Send + 'static, Global>
type Error = Box<dyn Error + Sync + Send + 'static, Global>
type Future = ResponseFuture<<T as Service<Request>>::Future>
type Future = ResponseFuture<<T as Service<Request>>::Future>
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Poll::Ready(Ok(()))
when the service is able to process requests. Read moreAuto Trait Implementations
impl<T, Request> !RefUnwindSafe for Buffer<T, Request>
impl<T, Request> Send for Buffer<T, Request>where
Request: Send,
<T as Service<Request>>::Future: Send,
impl<T, Request> Sync for Buffer<T, Request>where
Request: Send,
<T as Service<Request>>::Future: Send,
impl<T, Request> Unpin for Buffer<T, Request>
impl<T, Request> !UnwindSafe for Buffer<T, Request>
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
impl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
sourcefn ready(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, T::Error>;
where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, T::Error>;
where
Self: Sized,
T: Service<Request>, type Output = Result<&'a mut T, T::Error>;
sourcefn ready_and(&mut self) -> ReadyAnd<'_, Self, Request>where
Self: Sized,
fn ready_and(&mut self) -> ReadyAnd<'_, Self, Request>where
Self: Sized,
ServiceExt::ready
method insteadsourcefn 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,
T: Service<Request>, type Output = Result<T, T::Error>;
sourcefn oneshot(self, req: Request) -> Oneshot<Self, Request>ⓘNotable traits for Oneshot<S, Req>impl<S, Req> Future for Oneshot<S, Req>where
S: Service<Req>, type Output = Result<S::Response, S::Error>;
where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>ⓘNotable traits for Oneshot<S, Req>impl<S, Req> Future for Oneshot<S, Req>where
S: Service<Req>, type Output = Result<S::Response, S::Error>;
where
Self: Sized,
S: Service<Req>, type Output = Result<S::Response, S::Error>;
Service
, calling with the providing request once it is ready.sourcefn call_all<S>(self, reqs: S) -> CallAll<Self, S>where
Self: Sized,
Self::Error: Into<BoxError>,
S: Stream<Item = Request>,
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>where
Self: Sized,
Self::Error: Into<BoxError>,
S: Stream<Item = Request>,
sourcefn and_then<F>(self, f: F) -> AndThen<Self, F>where
Self: Sized,
F: Clone,
fn and_then<F>(self, f: F) -> AndThen<Self, F>where
Self: Sized,
F: Clone,
poll_ready
method. Read moresourcefn 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,
poll_ready
method. Read moresourcefn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where
Self: Sized,
F: FnOnce(Self::Error) -> Error + Clone,
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where
Self: Sized,
F: FnOnce(Self::Error) -> Error + Clone,
poll_ready
method. Read moresourcefn 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,
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,
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more