use alloc::collections::VecDeque;
use crate::MelinoeCell;
use super::BrandedVecDeque;
impl<'brand, T> BrandedVecDeque<'brand, T> {
#[inline]
pub fn push_back(&mut self, value: T) {
self.cells.push_back(MelinoeCell::new(value));
}
#[inline]
pub fn push_front(&mut self, value: T) {
self.cells.push_front(MelinoeCell::new(value));
}
#[inline]
pub fn pop_back(&mut self) -> Option<T> {
self.cells.pop_back().map(MelinoeCell::into_inner)
}
#[inline]
pub fn pop_front(&mut self) -> Option<T> {
self.cells.pop_front().map(MelinoeCell::into_inner)
}
#[inline]
pub fn clear(&mut self) {
self.cells.clear();
}
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.cells.reserve(additional);
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.cells.shrink_to_fit();
}
#[inline]
pub fn truncate(&mut self, len: usize) {
self.cells.truncate(len);
}
#[inline]
pub fn swap(&mut self, a: usize, b: usize) {
self.cells.swap(a, b);
}
#[inline]
pub fn drain<R>(&mut self, range: R) -> super::iter::BrandedVecDequeDrain<'_, 'brand, T>
where
R: core::ops::RangeBounds<usize>,
{
super::iter::BrandedVecDequeDrain {
inner: self.cells.drain(range),
}
}
#[inline]
#[must_use]
pub fn split_off(&mut self, at: usize) -> Self {
Self {
cells: self.cells.split_off(at),
}
}
#[inline]
pub fn append(&mut self, other: &mut Self) {
self.cells.append(&mut other.cells);
}
#[inline]
pub fn retain_mut<F>(&mut self, mut f: F)
where
F: FnMut(&mut T) -> bool,
{
self.cells.retain_mut(|cell| f(cell.get_mut()));
}
#[inline]
#[must_use]
pub fn into_vec_deque(self) -> VecDeque<T> {
unsafe {
let cells = core::mem::ManuallyDrop::new(self.cells);
core::ptr::read(core::ptr::addr_of!(*cells).cast::<VecDeque<T>>())
}
}
}