macro_rules! const_queue {
($ttype:ty; $size:expr) => { ... };
}Expand description
Creates a ConstBoundedQueue. This function exists mostly to creates queues of the correct size easily. For instance, to create a queue that can hold 2 values, the bound needs to be four. This macro assists with that by generating an initialization that takes this into account.
§Compile Error
Constant queues have a few limitations due to the inner workings of the ring:
- They must not be empty. You cannot create an
emptyring. - They must be powers of two. Thus only 1, 2, 4, etc. are valid.
§Example
use lfqueue::{const_queue, ConstBoundedQueue, ScqError};
// Let us create a constant queue of size 1.
let queue = const_queue!(usize; 1);
assert!(queue.enqueue(1).is_ok());
assert_eq!(queue.enqueue(2), Err(ScqError::QueueFull));
// Let us create a constant queue of size 8;
let queue = const_queue!(usize; 8);
for i in 0..8 {
assert!(queue.enqueue(i).is_ok());
}
assert!(queue.enqueue(0).is_err()); // queue full