Skip to main content

Resize

Trait Resize 

Source
pub trait Resize: MPMCQueue {
    // Required method
    fn resize(&self, size: usize) -> bool;
}
Expand description

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

This trait makes no guarantees regarding the synchronization model or blocking behavior of the resize 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, Resize};

 let q = DynamicQueue::new(1);

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

 assert!(q.resize(2 + q.capacity()));

 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 resize(&self, size: usize) -> bool

Attempts to resize the capacity of the queue to size 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 resize.

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> Resize for DynamicQueue<T, S>
where T: AsPackedValue, S: SlotType<T>,

Source§

impl<T, S> Resize 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>: Resize,