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
'notifieris the lifetime of the borrow of theNotifierwhich this sends messages to.Mis the type of message accepted by theNotifier.Lis the type ofListeneraccepted by theNotifier.CAPACITYis the maximum number of messages in one batch. The buffer memory is allocated in-line in theBuffervalue, soCAPACITYshould 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>,
impl<'notifier, M, L, const CAPACITY: usize> Buffer<'notifier, M, L, CAPACITY>where
L: Listener<M>,
Sourcepub fn push(&mut self, message: M)
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§
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>
impl<'notifier, M, L, const CAPACITY: usize> Sync for Buffer<'notifier, M, L, CAPACITY>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more