pub type DestaqueU8<T, const CAP: usize, S = Bare> = Destaque<T, CAP, u8, S>;
_destaque_u8
only.Expand description
📦
A Destaque
with an 8-bit index size.
Aliased Type§
struct DestaqueU8<T, const CAP: usize, S = Bare> { /* private fields */ }
Implementations
Source§impl<T: Copy, const CAP: usize> Destaque<T, CAP, u8, Bare>
impl<T: Copy, const CAP: usize> Destaque<T, CAP, u8, Bare>
Sourcepub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub const fn new_copied(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty destaque, allocated in the stack,
copying element
to fill the remaining free data, in compile-time.
§Errors
Returns MismatchedCapacity
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
const S: DestaqueU8<i32, 16> = unwrap![ok DestaqueU8::new_copied(0)];
Source§impl<T: Clone, const CAP: usize> Destaque<T, CAP, u8, Bare>
impl<T: Clone, const CAP: usize> Destaque<T, CAP, u8, Bare>
Sourcepub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
pub fn new(element: T) -> Result<Self, MismatchedCapacity> ⓘ
Returns an empty destaque, allocated in the stack,
cloning element
to fill the remaining free data.
§Errors
Returns MismatchedCapacity
if CAP >
u8::MAX
or if CAP > isize::MAX / size_of::<T>()
.
§Examples
let q = DestaqueU8::<_, 16>::new(0).unwrap();
Source§impl<T, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
Sourcepub fn from_array(arr: [T; CAP]) -> Destaque<T, CAP, u8, S>
pub fn from_array(arr: [T; CAP]) -> Destaque<T, CAP, u8, S>
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the destaque is empty.
§Examples
let q = DestaqueU8::<i32, 8>::default();
assert![q.is_empty()];
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the destaque is full.
§Examples
let q = DestaqueU8::<_, 3>::from([1, 2, 3]);
assert![q.is_full()];
Sourcepub const fn capacity(&self) -> u8
pub const fn capacity(&self) -> u8
Returns the destaque’s total capacity.
§Examples
let q = DestaqueU8::<i32, 3>::default();
assert_eq![3, q.capacity()];
Sourcepub const fn remaining_capacity(&self) -> u8
pub const fn remaining_capacity(&self) -> u8
Returns the destaque’s remaining capacity.
§Examples
let mut q = DestaqueU8::<i32, 3>::default();
assert_eq![3, q.remaining_capacity()];
q.push_back(1)?;
assert_eq![2, q.remaining_capacity()];
Sourcepub fn as_slices(&self) -> (&[T], &[T]) ⓘ
pub fn as_slices(&self) -> (&[T], &[T]) ⓘ
Returns the destaque as pair of shared slices, which contain, in order, the contents of the destaque.
§Examples
let q = DestaqueU8::<_, 3>::from([1, 2, 3]);
assert_eq![q.as_slices(), (&[1, 2, 3][..], &[][..])];
Sourcepub const fn is_contiguous(&self) -> bool
pub const fn is_contiguous(&self) -> bool
Returns true
if the destaque is contiguous.
§Examples
let mut q = DestaqueU8::<_, 3>::from([1, 2, 3]);
assert_eq![q.as_slices(), (&[1, 2, 3][..], &[][..])];
assert![q.is_contiguous()];
q.pop_back()?;
q.push_front(4)?;
assert![!q.is_contiguous()];
assert_eq![q.as_slices(), (&[4][..], &[1, 2][..])];
Sourcepub fn push_front(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push_front(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the front of the destaque.
( 1 2 -- 3 1 2 )
§Errors
Returns NotEnoughSpace
if the destaque is full.
§Examples
let mut q = DestaqueU8::<u8, 3>::default();
q.push_front(1)?;
q.push_front(2)?;
q.push_front(3)?;
assert_eq![q.to_array(), Some([3, 2, 1])];
Sourcepub fn push_front_unchecked(&mut self, element: T)
pub fn push_front_unchecked(&mut self, element: T)
Sourcepub fn push_front_override(&mut self, element: T) -> bool
pub fn push_front_override(&mut self, element: T) -> bool
Pushes a new element
to the front of the destaque,
overriding an element from the back if the destaque is full.
Returns true
if an element was overridden, and false
otherwise.
§Examples
let mut q = DestaqueU8::<_, 3>::from([1, 2]);
assert_eq!(q.push_front_override(3), false);
assert_eq![q.to_array(), Some([3, 1, 2])];
assert_eq!(q.push_front_override(4), true);
assert_eq![q.to_array(), Some([4, 3, 1])];
Sourcepub fn push_back(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn push_back(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Pushes a new element
to the back of the destaque.
This is the habitual enqueue operation for a single-ended queue.
( 1 2 -- 1 2 3 )
§Errors
Returns NotEnoughSpace
if the destaque is full.
§Examples
let mut q = DestaqueU8::<u8, 3>::default();
q.push_back(1)?;
q.push_back(2)?;
q.push_back(3)?;
assert_eq![q.to_array(), Some([1, 2, 3])];
Sourcepub fn enqueue(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
pub fn enqueue(&mut self, element: T) -> Result<(), NotEnoughSpace> ⓘ
Alias of push_back
.
This is the habitual enqueue operation for a single-ended queue.
Sourcepub fn push_back_unchecked(&mut self, element: T)
pub fn push_back_unchecked(&mut self, element: T)
Sourcepub fn push_back_override(&mut self, element: T) -> bool
pub fn push_back_override(&mut self, element: T) -> bool
Pushes a new element
to the back of the destaque,
overriding the first element if the destaque is full.
Returns true
if an element was overridden, and false
otherwise.
§Examples
let mut q = DestaqueU8::<_, 3>::from([1, 2]);
assert_eq!(q.push_back_override(3), false);
assert_eq![q.to_array(), Some([1, 2, 3])];
assert_eq!(q.push_back_override(4), true);
assert_eq![q.to_array(), Some([2, 3, 4])];
Sourcepub fn pop_front(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop_front(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the front element.
This is the habitual dequeue operation for a signle-ended queue.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the queue is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![1, q.pop_front()?];
assert_eq![2, q.pop_front()?];
assert_eq![3, q.pop_front()?];
assert![q.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn dequeue(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn dequeue(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Alias of pop_front
.
This is the habitual dequeue operation for a single-ended queue.
Sourcepub fn pop_back(&mut self) -> Result<T, NotEnoughElements> ⓘ
Available on crate feature unsafe_ptr
or Clone
only.
pub fn pop_back(&mut self) -> Result<T, NotEnoughElements> ⓘ
unsafe_ptr
or Clone
only.Pops the back element.
( 1 2-- 1 )
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![3, q.pop_back()?];
assert_eq![2, q.pop_back()?];
assert_eq![1, q.pop_back()?];
assert![q.is_empty()];
§Features
It’s depends on T: Clone
, unless the unsafe_ptr
feature is enabled.
Sourcepub fn peek_back(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_back(&self) -> Result<&T, NotEnoughElements> ⓘ
Returns a shared reference to the back element.
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&3, q.peek_back()?];
Sourcepub fn peek_back_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_back_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Returns an exclusive reference to the back element.
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&mut 3, q.peek_back_mut()?];
Sourcepub fn peek_nth_back(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth_back(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
Returns a shared reference to the nth
back element.
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least nth
elements.
§Examples
let q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&1, q.peek_nth_back(2)?];
Sourcepub fn peek_nth_back_mut(
&mut self,
nth: u8,
) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_back_mut( &mut self, nth: u8, ) -> Result<&mut T, NotEnoughElements> ⓘ
Returns an exclusive reference to the nth
back element.
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least nth
elements.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&mut 1, q.peek_nth_back_mut(2)?];
Sourcepub fn peek_front(&self) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_front(&self) -> Result<&T, NotEnoughElements> ⓘ
Returns a shared reference to the front element.
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&1, q.peek_front()?];
Sourcepub fn peek_front_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_front_mut(&mut self) -> Result<&mut T, NotEnoughElements> ⓘ
Returns an exclusive reference to the front element.
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3]);
assert_eq![&mut 1, q.peek_front_mut()?];
Sourcepub fn peek_nth_front(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
pub fn peek_nth_front(&self, nth: u8) -> Result<&T, NotEnoughElements> ⓘ
Returns a shared reference to the nth
front element.
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least nth
elements.
§Examples
let q = DestaqueU8::<_, 8>::from([1, 2, 3, 4]);
assert_eq![&3, q.peek_nth_front(2)?];
Sourcepub fn peek_nth_front_mut(
&mut self,
nth: u8,
) -> Result<&mut T, NotEnoughElements> ⓘ
pub fn peek_nth_front_mut( &mut self, nth: u8, ) -> Result<&mut T, NotEnoughElements> ⓘ
Returns an exclusive reference to the nth
front element.
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least nth
elements.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3, 4]);
assert_eq![&mut 3, q.peek_nth_front_mut(2)?];
Sourcepub const fn clear(&mut self)
pub const fn clear(&mut self)
Clears the destaque.
( 1 2 -- )
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3, 4]);
q.clear();
assert![q.is_empty()];
Sourcepub fn drop_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the back element.
( 1 2 -- 1 )
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2]);
q.drop_back()?;
assert_eq![q.to_array(), Some([1])];
Sourcepub fn drop_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
Drops the front element.
( 1 2 -- 2 )
§Errors
Returns NotEnoughElements
if the destaque is empty.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2]);
q.drop_front()?;
assert_eq![q.to_array(), Some([2])];
Sourcepub fn drop_n_back(&mut self, nth: u8) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n_back(&mut self, nth: u8) -> Result<(), NotEnoughElements> ⓘ
Drops n
elements from the back.
( 1 2 3 4 -- 1 )
for n = 3
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least nth
elements.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3, 4]);
q.drop_n_back(3)?;
assert_eq![q.to_array(), Some([1])];
Sourcepub fn drop_n_front(&mut self, nth: u8) -> Result<(), NotEnoughElements> ⓘ
pub fn drop_n_front(&mut self, nth: u8) -> Result<(), NotEnoughElements> ⓘ
Drops n
elements from the front.
( 1 2 3 4 -- 4 )
for n = 3
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least nth
elements.
§Examples
let mut q = DestaqueU8::<_, 8>::from([1, 2, 3, 4]);
q.drop_n_front(3)?;
assert_eq![q.to_array(), Some([4])];
Sourcepub fn swap_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the last two elements at the back of the destaque.
( 1 2 3 4 -- 1 2 4 3 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 2 elements.
§Examples
let mut q = DestaqueU8::<_, 4>::from([1, 2, 3, 4]);
q.swap_back();
assert_eq![q.to_array(), Some([1, 2, 4, 3])];
Sourcepub fn swap_back_unchecked(&mut self)
pub fn swap_back_unchecked(&mut self)
Sourcepub fn swap_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the first two elements at the front of the destaque.
( 1 2 3 4 -- 2 1 3 4 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 2 elements.
§Examples
let mut q = DestaqueU8::<_, 4>::from([1, 2, 3, 4]);
q.swap_front();
assert_eq![q.to_array(), Some([2, 1, 3, 4])];
Sourcepub fn swap_front_unchecked(&mut self)
pub fn swap_front_unchecked(&mut self)
Unchecked version of swap_front
.
§Panics
Panics if the destaque doesn’t contain at least 2 elements.
Sourcepub fn swap2_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2_back(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the last two pairs of elements at the back of the destaque.
( 1 2 3 4 5 6 7 8 -- 1 2 3 4 7 8 5 6 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 2 elements.
§Examples
let mut q = DestaqueU8::<_, 16>::from([1, 2, 3, 4, 5, 6, 7, 8]);
q.swap2_back();
assert_eq![q.to_array(), Some([1, 2, 3, 4, 7, 8, 5, 6])];
Sourcepub fn swap2_back_unchecked(&mut self)
pub fn swap2_back_unchecked(&mut self)
Unchecked version of swap2_back
.
§Panics
Panics if the destaque doesn’t contain at least 2 elements.
Sourcepub fn swap2_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2_front(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the first two pairs of elements at the front of the destaque.
( 1 2 3 4 5 6 7 8 -- 3 4 1 2 5 6 7 8 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 4 elements.
§Examples
let mut q = DestaqueU8::<_, 16>::from([1, 2, 3, 4, 5, 6, 7, 8]);
q.swap2_front();
assert_eq![q.to_array(), Some([3, 4, 1, 2, 5, 6, 7, 8])];
Sourcepub fn swap2_front_unchecked(&mut self)
pub fn swap2_front_unchecked(&mut self)
Unchecked version of swap2_back
.
§Panics
Panics if the destaque doesn’t contain at least 2 elements.
Sourcepub fn swap_ends(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap_ends(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the front and back elements.
( 1 2 3 4 -- 4 2 3 1 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 2 elements.
§Examples
let mut q = DestaqueU8::<_, 6>::from([1, 2, 3, 4, 5]);
q.swap_ends();
assert_eq![q.to_array(), Some([5, 2, 3, 4, 1])];
Sourcepub fn swap2_ends(&mut self) -> Result<(), NotEnoughElements> ⓘ
pub fn swap2_ends(&mut self) -> Result<(), NotEnoughElements> ⓘ
Swaps the front and back pairs of elements.
( 1 2 3 4 5 6 7 8 -- 7 8 3 4 5 6 1 2 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t contain at least 4 elements.
§Examples
let mut q = DestaqueU8::<_, 16>::from([1, 2, 3, 4, 5, 6, 7, 8]);
q.swap2_ends();
assert_eq![q.to_array(), Some([7, 8, 3, 4, 5, 6, 1, 2])];
Sourcepub fn rot_right(&mut self)
pub fn rot_right(&mut self)
Rotates all the destaqued elements one place to the right.
( 1 2 3 4 -- 4 1 2 3 )
§Examples
let mut q = DestaqueU8::<i32, 8>::from([2, 3]);
q.push_front(1)?;
q.push_back(4)?;
assert_eq![q.to_array(), Some([1, 2, 3, 4])];
q.rot_right();
assert_eq![q.to_array(), Some([4, 1, 2, 3])];
Sourcepub fn rot_right_n(&mut self, nth: u8)
pub fn rot_right_n(&mut self, nth: u8)
Rotates all the destaqued elements n
places to the right.
( 1 2 3 4 -- 2 3 4 1 )
for n = 3
§Examples
let mut q = DestaqueU8::<i32, 8>::from([2, 3]);
q.push_front(1)?;
q.push_back(4)?;
assert_eq![q.to_array(), Some([1, 2, 3, 4])];
q.rot_right_n(3);
assert_eq![q.to_array(), Some([2, 3, 4, 1])];
Sourcepub fn rot_left(&mut self)
pub fn rot_left(&mut self)
Rotates all the destaqued elements one place to the left.
( 1 2 3 4 -- 2 3 4 1 )
§Examples
let mut q = DestaqueU8::<i32, 8>::from([2, 3]);
q.push_front(1)?;
q.push_back(4)?;
assert_eq![q.to_array(), Some([1, 2, 3, 4])];
q.rot_left();
assert_eq![q.to_array(), Some([2, 3, 4, 1])];
Sourcepub fn rot_left_n(&mut self, nth: u8)
pub fn rot_left_n(&mut self, nth: u8)
Rotates all the destaqued elements n
places to the left.
( 1 2 3 4 -- 4 1 2 3 )
for nth = 3
§Examples
let mut q = DestaqueU8::<i32, 8>::from([2, 3]);
q.push_front(1)?;
q.push_back(4)?;
assert_eq![q.to_array(), Some([1, 2, 3, 4])];
q.rot_left_n(3);
assert_eq![q.to_array(), Some([4, 1, 2, 3])];
Source§impl<T, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
Sourcepub const fn iter(&self) -> DestaqueIter<'_, T, CAP, u8, S> ⓘ
pub const fn iter(&self) -> DestaqueIter<'_, T, CAP, u8, S> ⓘ
Returns an iterator.
Sourcepub fn extend_back<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend_back<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the back of the destaque from an iterator.
( 1 2 -- 1 2 3 4 5 6)
for [3 4 5 6]
§Errors
Returns NotEnoughSpace
if the destaque becomes full before the iterator finishes.
§Examples
let mut q = DestaqueU8::<_, 6>::from([1, 2, 3]);
q.extend_back([4, 5, 6, 7, 8]);
assert_eq![q.to_array(), Some([1, 2, 3, 4, 5, 6])];
Sourcepub fn extend_back_override<I>(&mut self, iterator: I) -> boolwhere
I: IntoIterator<Item = T>,
pub fn extend_back_override<I>(&mut self, iterator: I) -> boolwhere
I: IntoIterator<Item = T>,
Extends the back of the destaque from an iterator, overriding elements from the front if the destaque is full.
( 1 2 3 -- 3 4 5 6)
for [4 5 6]
and CAP = 4
§Examples
let mut q = DestaqueU8::<_, 4>::from([1, 2, 3]);
assert_eq![q.extend_back_override([4, 5, 6]), true];
assert_eq![q.to_array(), Some([3, 4, 5, 6])];
Sourcepub fn extend_front<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
pub fn extend_front<I>(&mut self, iterator: I) -> Result<(), NotEnoughSpace> ⓘwhere
I: IntoIterator<Item = T>,
Extends the front of the destaque from an iterator.
( 1 2 -- 6 5 4 3 1 2 )
for [3 4 5 6]
§Errors
Returns NotEnoughSpace
if the destaque becomes full before the iterator finishes.
§Examples
let mut q = DestaqueU8::<_, 6>::from([1, 2, 3]);
q.extend_front([4, 5, 6, 7, 8]);
assert_eq![q.to_array(), Some([6, 5, 4, 1, 2, 3])];
Sourcepub fn extend_front_override<I>(&mut self, iterator: I) -> boolwhere
I: IntoIterator<Item = T>,
pub fn extend_front_override<I>(&mut self, iterator: I) -> boolwhere
I: IntoIterator<Item = T>,
Extends the front of the destaque from an iterator, overriding elements from the back if the destaque is full.
( 1 2 3 -- 6 5 4 1)
for [4 5 6]
and CAP = 4
§Examples
let mut q = DestaqueU8::<_, 4>::from([1, 2, 3]);
assert_eq![q.extend_front_override([4, 5, 6]), true];
assert_eq![q.to_array(), Some([6, 5, 4, 1])];
Source§impl<T: Clone, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
impl<T: Clone, const CAP: usize, S: Storage> Destaque<T, CAP, u8, S>
Sourcepub fn make_contiguous(&mut self, element: T) -> &mut [T] ⓘ
pub fn make_contiguous(&mut self, element: T) -> &mut [T] ⓘ
Makes the elements of the destaque contiguous, rearranging the elements so that they are in a single, continuous block starting from the front.
This operation might rearrange the internal representation of the elements to ensure they are contiguous. It clones the default element provided during the destaque’s construction to fill any gaps if necessary.
Returns a mutable slice to the now contiguous elements.
§Examples
let mut q = DestaqueU8::<_, 5>::new(0).unwrap();
q.push_back(1);
q.push_back(2);
q.push_front(5);
assert_eq!(q.as_slices(), (&[5][..], &[1, 2][..]));
assert_eq!(q.make_contiguous(0), &[5, 1, 2]);
assert_eq!(q.as_slices(), (&[5, 1, 2][..], &[][..]));
Sourcepub fn to_vec(&self) -> Vec<T> ⓘ
Available on crate feature alloc
only.
pub fn to_vec(&self) -> Vec<T> ⓘ
alloc
only.Returns the destaqued elements as a vector.
§Examples
let mut q = DestaqueU8::<_, 5>::from([3, 4]);
q.push_front(2)?;
q.push_back(5)?;
q.push_front(1)?;
assert_eq![q.to_vec(), vec![1, 2, 3, 4, 5]];
Sourcepub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
pub fn to_array<const LEN: usize>(&self) -> Option<[T; LEN]> ⓘ
Returns some LEN
destaqued elements as an array, or None
if the destaque
is empty, or there are not at least LEN
elements.
This is a non alloc
alternative method to to_vec
.
§Panics
Panics if the new LEN
sized array can’t be allocated.
§Examples
let mut q = DestaqueU8::<_, 5>::from([3, 4]);
q.push_front(2)?;
q.push_back(5)?;
q.push_front(1)?;
assert_eq![q.to_array::<5>(), Some([1, 2, 3, 4, 5])];
§Features
Makes use of the unsafe_array
feature if enabled.
Sourcepub fn dup_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the back element at the back
( 1 2 -- 1 2 2 )
§Errors
Returns NotEnoughElements
if the destaque is empty
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 4>::from([1, 2, 3]);
q.dup_back()?;
assert_eq![q.to_array(), Some([1, 2, 3, 3])];
Sourcepub fn dup_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the front element at the front.
( 1 2 -- 1 1 2 )
§Errors
Returns NotEnoughElements
if the destaque is empty
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 4>::from([1, 2, 3]);
q.dup_front()?;
assert_eq![q.to_array(), Some([1, 1, 2, 3])];
Sourcepub fn dup2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the back pair of elements, at the back.
( 1 2 3 4 -- 1 2 3 4 3 4)
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 6>::from([1, 2, 3, 4]);
q.dup2_back()?;
assert_eq![q.to_array(), Some([1, 2, 3, 4, 3, 4])];
Sourcepub fn dup2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn dup2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the front pair of elements, at the front.
( 1 2 3 4 -- 1 2 1 2 3 4)
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 6>::from([1, 2, 3, 4]);
q.dup2_front()?;
assert_eq![q.to_array(), Some([1, 2, 1, 2, 3, 4])];
Sourcepub fn over_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the second back element, at the back.
( 1 2 3 4 -- 1 2 3 4 3 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4]);
q.over_back()?;
assert_eq![q.to_array(), Some([1, 2, 3, 4, 3])];
Sourcepub fn over_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the second front element, at the front.
( 1 2 3 4 -- 2 1 2 3 4 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4]);
q.over_front()?;
assert_eq![q.to_array(), Some([2, 1, 2, 3, 4])];
Sourcepub fn over2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the second back pair of elements, at the back.
( 1 2 3 4 5 6 7 8 -- 1 2 3 4 5 6 7 8 5 6 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 4 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 8>::from([1, 2, 3, 4, 5, 6]);
q.over2_back()?;
assert_eq![q.to_array(), Some([1, 2, 3, 4, 5, 6, 3, 4])];
Sourcepub fn over2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn over2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the second front pair of elements, at the front.
( 1 2 3 4 5 6 7 8 -- 3 4 1 2 3 4 5 6 7 8 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 4 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 8>::from([1, 2, 3, 4, 5, 6]);
q.over2_front()?;
assert_eq![q.to_array(), Some([3, 4, 1, 2, 3, 4, 5, 6])];
Sourcepub fn tuck_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the back element, before the second back element.
( 1 2 3 4 -- 1 2 4 3 4 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4, 5]);
q.tuck_back()?;
assert_eq![q.to_array(), Some([1, 2, 3, 5, 4, 5])];
Sourcepub fn tuck_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the front element, after the second front element.
( 1 2 3 4 -- 1 2 1 3 4 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 2 elements,
or NotEnoughSpace
if it is full.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4, 5]);
q.tuck_front()?;
assert_eq![q.to_array(), Some([1, 2, 1, 3, 4, 5])];
Sourcepub fn tuck2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2_back(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the back pair of elements, before the second back pair of elements.
( 1 2 3 4 5 6 7 8 -- 1 2 3 4 7 8 5 6 7 8 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 4 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4, 5]);
q.tuck2_back()?;
assert_eq![q.to_array(), Some([1, 4, 5, 2, 3, 4, 5])];
Sourcepub fn tuck2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
pub fn tuck2_front(&mut self) -> Result<(), DataNotEnough> ⓘ
Duplicates the front pair of elements, after the second front pair of elements.
( 1 2 3 4 5 6 7 8 -- 1 2 3 4 1 2 5 6 7 8 )
§Errors
Returns NotEnoughElements
if the destaque doesn’t have at least 4 elements,
or NotEnoughSpace
if it doesn’t have space for 2 additional elements.
§Examples
let mut q = DestaqueU8::<u8, 7>::from([1, 2, 3, 4, 5]);
q.tuck2_front()?;
assert_eq![q.to_array(), Some([1, 2, 3, 4, 1, 2, 5])];
impl<T: Clone, const CAP: usize> Destaque<T, CAP, u8, Bare>
Trait Implementations
Source§impl<T: ConstDefault, const CAP: usize, IDX: ConstDefault> ConstDefault for Destaque<T, CAP, IDX, Bare>
impl<T: ConstDefault, const CAP: usize, IDX: ConstDefault> ConstDefault for Destaque<T, CAP, IDX, Bare>
Source§impl<T, const LEN: usize, S: Storage> DataCollection for Destaque<T, LEN, u8, S>
impl<T, const LEN: usize, S: Storage> DataCollection for Destaque<T, LEN, u8, S>
Source§fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_capacity(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
fn collection_len(&self) -> Result<usize, NotAvailable> ⓘ
Source§fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_empty(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is empty, false
if it’s not.Source§fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
fn collection_is_full(&self) -> Result<bool, NotAvailable> ⓘ
true
if the collection is full, false
if it’s not.Source§fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_contains(
&self,
element: Self::Element,
) -> Result<bool, NotAvailable> ⓘwhere
T: PartialEq,
true
if the collection contains the given element
.Source§fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
fn collection_count(
&self,
element: &Self::Element,
) -> Result<usize, NotAvailable> ⓘwhere
T: PartialEq,
element
appears in the collection.Source§impl<T, const CAP: usize, S: Storage> DataDeque for Destaque<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> DataDeque for Destaque<T, CAP, u8, S>
Source§fn queue_pop_back(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn queue_pop_back( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn queue_push_front(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn queue_push_front( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§fn queue_pop_front(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn queue_pop_front( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn queue_push_back(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn queue_push_back( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
queue_push
). Read moreSource§impl<T, const CAP: usize, S: Storage> DataDesta for Destaque<T, CAP, u8, S>
impl<T, const CAP: usize, S: Storage> DataDesta for Destaque<T, CAP, u8, S>
Source§fn stack_pop_front(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop_front( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
Source§fn stack_push_front(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push_front( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
Source§fn stack_pop_back(
&mut self,
) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
fn stack_pop_back( &mut self, ) -> Result<<Self as DataCollection>::Element, NotEnoughElements> ⓘ
DataStack::stack_pop
).Source§fn stack_push_back(
&mut self,
element: <Self as DataCollection>::Element,
) -> Result<(), NotEnoughSpace> ⓘ
fn stack_push_back( &mut self, element: <Self as DataCollection>::Element, ) -> Result<(), NotEnoughSpace> ⓘ
DataStack::stack_push
).