Skip to main content

BufferedContext

Struct BufferedContext 

Source
pub struct BufferedContext<S: Service> { /* private fields */ }
Expand description

A buffered service context.

This ServiceContext implementation is a wrapper around a service that provides a mailbox for input events and a mailbox for output events. The mailboxes are implemented as FIFO queues based on VecDeque.

The input mailbox acts as a buffer for the events that are sent to the service. The events are enqueued into the mailbox by calling the do_send method. The mailbox events are processed by the service on the next BufferedContext::poll call (see poll for more details).

The service context implements Deref trait to the inner service, so it can be used as the wrapped service itself.

Implementations§

Source§

impl<S: Service> BufferedContext<S>

Public API,

Source

pub fn new(service: S) -> Self

Create a new service context for the given service.

Source

pub fn service(&self) -> &S

Get a reference to the inner service.

Trait Implementations§

Source§

impl<S: Service + Default> Default for BufferedContext<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S: Service> Deref for BufferedContext<S>

Source§

type Target = S

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<S: Service> ServiceContext for BufferedContext<S>

Source§

fn do_send(&mut self, ev: S::InEvent)

Sends a message unconditionally, ignoring any potential errors.

The event will be enqueued into the service input mailbox and will be processed by the service on the next BufferedContext::poll call. See poll for more details.

Source§

fn poll(&mut self, cx: &mut TaskContext<'_>) -> Poll<S::OutEvent>

Poll the service for events.

The service polling process consists of the following steps:

  1. Poll the service for events. This triggers the Service::poll method, allowing the service to emit events.

    If the poll method returns a Poll::Ready event, the polling process will stop any further polling and the event will be returned to the downstream service.

  2. Process all the service output mailbox events. This drains the output mailbox and returns the events to the downstream service.

Source§

type InEvent = <S as Service>::InEvent

The input event type.
Source§

type OutEvent = <S as Service>::OutEvent

The output event type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.