Skip to main content

Growable

Trait Growable 

Source
pub trait Growable: MPMCQueue {
    // Required method
    fn grow_by(&self, by: usize) -> bool;
}
Expand description

An extension trait for MPMCQueue that allows dynamic growth of the queue.

This trait makes no guarantees regarding the synchronization model or blocking behavior of the grow_by method itself. It only guarantees that the core MPMCQueue operations maintain their original guarantees.

§Examples

#[cfg(feature = "dynamic")]
fn run() {
 use nblf_queue::{DynamicQueue, MPMCQueue, Growable};

 let q = DynamicQueue::new(1);

 assert!(q.push(1).is_ok());
 assert!(q.is_full());

 assert!(q.grow_by(2));

 assert_eq!(q.capacity(), 3);
 assert!(!q.is_full());

 assert!(q.push(2).is_ok());
 assert!(q.push(3).is_ok());

 assert_eq!(q.pop(), Some(1));
 assert_eq!(q.pop(), Some(2));
 assert_eq!(q.pop(), Some(3));

 assert!(q.is_empty());
}

#[cfg(feature = "dynamic")]
run();

Required Methods§

Source

fn grow_by(&self, by: usize) -> bool

Attempts to grow the capacity of the queue by by slots.

Note: This method may block or fail spuriously. Further a growth event may not be considered finished until some time after the call to grow_by.

Returns true if the resize was successfull, or false if it failed. Failure can occur due to allocator exhaustion, thread contention, or other implementation-specific conditions.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, S> Growable for DynamicQueue<T, S>
where T: AsPackedValue, S: SlotType<T>,

Source§

impl<T, S> Growable for PooledDynamicQueue<T, S>
where S: SlotType<ItemHandle<T>>, GrowableQueueCore<T, Pooled<T, QueueCore<BoxedBuffer<S::Slot>>, BoxedBuffer<UnsafeCell<Option<T>>>, QueueCore<BoxedBuffer<<Auto as SlotType<ItemHandle<()>>>::Slot>>>, S>: Growable,