Struct Buffer
pub struct Buffer<Req, F> { /* private fields */ }
Adds an mpsc buffer in front of an inner service.
See the module documentation for more details.
Implementations
impl<Req, F> Buffer<Req, F>
where
F: 'static,
fn new<S>(service: S, bound: usize) -> Self where S: Service<Req, Future = F> + Send + 'static, F: Send, S::Error: Into<BoxError> + Send + Sync, Req: Send + 'static,Creates a new
Bufferwrappingservice.boundgives 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
boundWhen
Buffer's implementation ofpoll_readyreturnsPoll::Ready, it reserves a slot in the channel for the forthcomingcall. 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 setboundto be at least the maximum number of concurrent requests theBufferwill see. If you do not, all the slots in the buffer may be held up by futures that have just calledpoll_readybut will not issue acall, which prevents other senders from issuing new requests.fn pair<S>(service: S, bound: usize) -> (Self, Worker<S, Req>) where S: Service<Req, Future = F> + Send + 'static, F: Send, S::Error: Into<BoxError> + Send + Sync, Req: Send + 'static,Creates a new
Bufferwrappingservice, but returns the background worker.This is useful if you do not want to spawn directly onto the tokio runtime but instead want to use your own executor. This will return the
Bufferand the backgroundWorkerthat you can then spawn.
Trait Implementations
impl<Req, F> Clone for Buffer<Req, F>
where
Req: Send + 'static,
F: Send + 'static,
fn clone(&self) -> Self
impl<Req, Rsp, F, E> Service<Req> for Buffer<Req, F>
where
F: Future<Output = Result<Rsp, E>> + Send + 'static,
E: Into<BoxError>,
Req: Send + 'static,
type Response = Rsp;type Error = Box<dyn Error + Sync + Send>;type Future = ResponseFuture<F>;fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn call(&mut self, request: Req) -> Self::Future
impl<Req: Debug, F: Debug> Debug for Buffer<Req, F>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<Req, F> !RefUnwindSafe for Buffer<Req, F>
impl<Req, F> !UnwindSafe for Buffer<Req, F>
impl<Req, F> Freeze for Buffer<Req, F>
where
PollSender<Message<Req, F>>: Freeze,
impl<Req, F> Send for Buffer<Req, F>
where
PollSender<Message<Req, F>>: Send,
impl<Req, F> Sync for Buffer<Req, F>
where
PollSender<Message<Req, F>>: Sync,
impl<Req, F> Unpin for Buffer<Req, F>
where
PollSender<Message<Req, F>>: Unpin,
impl<Req, F> UnsafeUnpin for Buffer<Req, F>
where
PollSender<Message<Req, F>>: UnsafeUnpin,
Blanket Implementations
impl<C, Target> MakeConnection<Target> for Buffer<Req, F>
where
C: Service<Target>,
<C as Service<Target>>::Response: AsyncRead + AsyncWrite,
type Connection = <C as Service<Target>>::Response;type Error = <C as Service<Target>>::Error;type Future = <C as Service<Target>>::Future;fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), <C as MakeConnection<Target>>::Error>>fn make_connection(&mut self, target: Target) -> <C as MakeConnection<Target>>::Future
impl<M, S, Target, Request> MakeService<Target, Request> for Buffer<Req, F>
where
M: Service<Target, Response = S>,
S: Service<Request>,
type Response = <S as Service<Request>>::Response;type Error = <S as Service<Request>>::Error;type Service = S;type MakeError = <M as Service<Target>>::Error;type Future = <M as Service<Target>>::Future;fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>fn make_service(&mut self, target: Target) -> <M as MakeService<Target, Request>>::Future
impl<T> Any for Buffer<Req, F>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Buffer<Req, F>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Buffer<Req, F>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Buffer<Req, F>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Buffer<Req, F>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for Buffer<Req, F>
impl<T> ToOwned for Buffer<Req, F>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> WithSubscriber for Buffer<Req, F>
impl<T, Request> ServiceExt<Request> for Buffer<Req, F>
where
T: Service<Request> + ?Sized,
impl<T, U> Into<U> for Buffer<Req, F>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Buffer<Req, F>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Buffer<Req, F>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>