Buffer

Struct Buffer 

Source
pub struct Buffer<'notifier, M, L, const CAPACITY: usize>
where L: Listener<M>,
{ /* private fields */ }
Expand description

Buffers messages that are to be sent through a Notifier, for efficiency.

Messages may be added to the buffer, and when the buffer contains CAPACITY messages or when it is dropped, they are all sent through Notifier::notify_many() at once. This is intended to increase performance by invoking each listener once per batch instead of once per message.

Create a Buffer by calling Notifier::buffer().

§Generic parameters

  • 'notifier is the lifetime of the borrow of the Notifier which this sends messages to.
  • M is the type of message accepted by the Notifier.
  • L is the type of Listener accepted by the Notifier.
  • CAPACITY is the maximum number of messages in one batch. The buffer memory is allocated in-line in the Buffer value, so CAPACITY should be chosen with consideration for stack memory usage.

Implementations§

Source§

impl<'notifier, M, L, const CAPACITY: usize> Buffer<'notifier, M, L, CAPACITY>
where L: Listener<M>,

Source

pub fn push(&mut self, message: M)

Store a message in this buffer, to be delivered later as if by Notifier::notify().

If the buffer becomes full when this message is added, then the messages in the buffer will be delivered before push() returns. Otherwise, they will be delivered when the Buffer is dropped.

Trait Implementations§

Source§

impl<'notifier, M: Debug, L, const CAPACITY: usize> Debug for Buffer<'notifier, M, L, CAPACITY>
where L: Listener<M> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M, L, const CAPACITY: usize> Drop for Buffer<'_, M, L, CAPACITY>
where L: Listener<M>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'notifier, M, L, const CAPACITY: usize> Freeze for Buffer<'notifier, M, L, CAPACITY>
where M: Freeze,

§

impl<'notifier, M, L, const CAPACITY: usize> !RefUnwindSafe for Buffer<'notifier, M, L, CAPACITY>

§

impl<'notifier, M, L, const CAPACITY: usize> Send for Buffer<'notifier, M, L, CAPACITY>
where M: Send, L: Send + Sync,

§

impl<'notifier, M, L, const CAPACITY: usize> Sync for Buffer<'notifier, M, L, CAPACITY>
where M: Sync, L: Send + Sync,

§

impl<'notifier, M, L, const CAPACITY: usize> Unpin for Buffer<'notifier, M, L, CAPACITY>
where M: Unpin,

§

impl<'notifier, M, L, const CAPACITY: usize> !UnwindSafe for Buffer<'notifier, M, L, CAPACITY>

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.