pub type DstQueueUsize<DST, const CAP: usize> = DstQueue<DST, DstArray<usize, CAP>>;
Available on crate feature
unsafe_layout
only.Expand description
📦 A statically allocated FIFO queue of DSTs with pointer alignment.
§Examples
let mut queue = DstQueueUsize::<[u8], 16>::new();
queue.push_copied(&[1]);
Aliased Type§
struct DstQueueUsize<DST, const CAP: usize> { /* private fields */ }
Implementations
Source§impl<BUF: DstBuf, DST> DstQueue<[DST], BUF>where
(DST, BUF::Inner): MemAligned,
impl<BUF: DstBuf, DST> DstQueue<[DST], BUF>where
(DST, BUF::Inner): MemAligned,
Sourcepub fn push_cloned(&mut self, slice: &[DST]) -> Result<(), ()> ⓘwhere
DST: Clone,
pub fn push_cloned(&mut self, slice: &[DST]) -> Result<(), ()> ⓘwhere
DST: Clone,
Pushes a set of items (cloning out of the input slice
).
§Examples
let mut queue = DstQueue::<[String], DstArray<usize, 8>>::new();
queue.push_cloned(&["1".to_owned()]);
Sourcepub fn push_copied(&mut self, slice: &[DST]) -> Result<(), ()> ⓘwhere
DST: Copy,
pub fn push_copied(&mut self, slice: &[DST]) -> Result<(), ()> ⓘwhere
DST: Copy,
Pushes a set of items (copying out of the input slice
).
§Examples
let mut queue = DstQueue::<[usize], DstArray<usize, 8>>::new();
queue.push_copied(&[1]);
Sourcepub fn push_from_iter(
&mut self,
iter: impl ExactSizeIterator<Item = DST>,
) -> Result<(), ()> ⓘ
pub fn push_from_iter( &mut self, iter: impl ExactSizeIterator<Item = DST>, ) -> Result<(), ()> ⓘ
Pushes an item, populated from an exact-sized iterator.
§Examples
let mut stack = DstQueue::<[u8], DstArray<usize, 8>>::new();
stack.push_from_iter(0..10);
assert_eq!(stack.front().unwrap(), &[0,1,2,3,4,5,6,7,8,9]);
Source§impl<DST: ?Sized, BUF: DstBuf> DstQueue<DST, BUF>
impl<DST: ?Sized, BUF: DstBuf> DstQueue<DST, BUF>
Sourcepub fn with_buffer(data: BUF) -> Self
pub fn with_buffer(data: BUF) -> Self
Constructs a new (empty) queue using the given buffer
.
Sourcepub fn push_back<VAL, F>(&mut self, value: VAL, f: F) -> Result<(), VAL> ⓘ
pub fn push_back<VAL, F>(&mut self, value: VAL, f: F) -> Result<(), VAL> ⓘ
Pushes a value to the end of the queue.
Sourcepub fn pop_front(&mut self) -> Option<DstQueuePopHandle<'_, DST, BUF>> ⓘ
pub fn pop_front(&mut self) -> Option<DstQueuePopHandle<'_, DST, BUF>> ⓘ
Removes an item from the front of the queue.
Sourcepub fn front_mut(&mut self) -> Option<&mut DST> ⓘ
pub fn front_mut(&mut self) -> Option<&mut DST> ⓘ
Returns an exclusive reference to the front element.
Sourcepub const fn iter(&self) -> DstQueueIter<'_, DST, BUF> ⓘ
pub const fn iter(&self) -> DstQueueIter<'_, DST, BUF> ⓘ
Returns an immutable iterator (yields references to items, in insertion order).
§Examples
let mut list = DstQueue::<str, DstArray<usize, 8>>::new();
list.push_back_str("Hello");
list.push_back_str("world");
let mut it = list.iter();
assert_eq!(it.next(), Some("Hello"));
assert_eq!(it.next(), Some("world"));
assert_eq!(it.next(), None);
Sourcepub fn iter_mut(&mut self) -> DstQueueIterMut<'_, DST, BUF> ⓘ
pub fn iter_mut(&mut self) -> DstQueueIterMut<'_, DST, BUF> ⓘ
Returns a mutable iterator.
§Examples
let mut list = DstQueue::<[u8], DstArray<usize, 8>>::new();
list.push_copied(&[1,2,3]);
list.push_copied(&[9]);
for v in list.iter_mut() {
v[0] -= 1;
}
let mut it = list.iter();
assert_eq!(it.next(), Some(&[0,2,3][..]));
assert_eq!(it.next(), Some(&[8][..]));
assert_eq!(it.next(), None);
Sourcepub fn retain<Cb>(&mut self, cb: Cb)
pub fn retain<Cb>(&mut self, cb: Cb)
Removes any items that don’t meet a predicate.
§Examples
trait DebugAny: 'static + Any + Debug { fn as_any(&self) -> &dyn Any; }
impl<DST: Debug + Any + 'static> DebugAny for DST { fn as_any(&self) -> &dyn Any { self } }
let mut list = {
let mut list: DstQueue<dyn DebugAny, DstArray<usize, 8>> = DstQueue::new();
list.push_back(1234, |v| v);
list.push_back(234.5f32, |v| v);
list.push_back(5678, |v| v);
list.push_back(0.5f32, |v| v);
list
};
list.retain(|v| (*v).as_any().downcast_ref::<f32>().is_some());
let mut it = list.iter().map(|v| format!("{:?}", v));
assert_eq!(it.next(), Some("234.5".to_owned()));
assert_eq!(it.next(), Some("0.5".to_owned()));
assert_eq!(it.next(), None);