pub struct BoundedQueue<T> { /* private fields */ }Expand description
Bounded message queue for a peer
Provides a FIFO queue with configurable maximum size. When full, oldest messages are dropped (or operations fail).
Implementations§
Source§impl<T> BoundedQueue<T>
impl<T> BoundedQueue<T>
Sourcepub fn new(max_size: usize) -> BoundedQueue<T>
pub fn new(max_size: usize) -> BoundedQueue<T>
Create a new bounded queue
Sourcepub fn enqueue(&mut self, item: T) -> Option<T>
pub fn enqueue(&mut self, item: T) -> Option<T>
Enqueue a message, dropping oldest if full
Returns the dropped message if one was evicted, None otherwise.
Sourcepub fn try_enqueue(&mut self, item: T) -> Result<(), T>
pub fn try_enqueue(&mut self, item: T) -> Result<(), T>
Try to enqueue a message, failing if full
Returns Ok(()) if enqueued, Err if queue is full.
Sourcepub fn total_enqueued(&self) -> u64
pub fn total_enqueued(&self) -> u64
Get total messages enqueued (all time)
Sourcepub fn total_dropped(&self) -> u64
pub fn total_dropped(&self) -> u64
Get total messages dropped due to overflow
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for BoundedQueue<T>
impl<T> RefUnwindSafe for BoundedQueue<T>where
T: RefUnwindSafe,
impl<T> Send for BoundedQueue<T>where
T: Send,
impl<T> Sync for BoundedQueue<T>where
T: Sync,
impl<T> Unpin for BoundedQueue<T>where
T: Unpin,
impl<T> UnsafeUnpin for BoundedQueue<T>
impl<T> UnwindSafe for BoundedQueue<T>where
T: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more