pub struct ConstFixedArray<const TSIZE: usize, T: Sized + Copy> { /* private fields */ }Expand description
A fixed-capacity array. This type is a const (as in: compile time) analogue of FixedArray.
§Notes
For the array to be usable in const context, the T type needs to be Copy (which implies “no Drop”).
And in that case ConstFixedArray doesn’t need to be (and actually cannot be to work in const context)
Drop as well.
Unlike FixedArray, this type does not implement
any of the convenient traits such as ImmutableArray
or PartialEq. These are NOT usable in const context anyway.
Implementations§
Source§impl<const TSIZE: usize, T: Sized + Copy> ConstFixedArray<TSIZE, T>
impl<const TSIZE: usize, T: Sized + Copy> ConstFixedArray<TSIZE, T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new, empty ConstFixedArray.
§Panics
This function will panic if the TSIZE is invalid, i.e.
when either TSIZE is 0 or exceeds [Length::MAX_LENGTH].
Sourcepub const fn length(&self) -> Length
pub const fn length(&self) -> Length
Returns the length of the ConstFixedArray.
pub const fn is_empty(&self) -> bool
Sourcepub const fn capacity(&self) -> Length
pub const fn capacity(&self) -> Length
Returns the capacity of the ConstFixedArray. This is TSIZE
as [Length].
Sourcepub const fn as_slice_const(&self) -> &[T]
pub const fn as_slice_const(&self) -> &[T]
Returns the ConstFixedArray as immutable slice.
Sourcepub const fn as_slice_mut_const(&mut self) -> &mut [T]
pub const fn as_slice_mut_const(&mut self) -> &mut [T]
Returns the ConstFixedArray as mutable slice.
Sourcepub const fn try_push_array_const<const TARRSIZE: usize>(
&mut self,
arr: [T; TARRSIZE],
) -> Result<(), ArrayError>
pub const fn try_push_array_const<const TARRSIZE: usize>( &mut self, arr: [T; TARRSIZE], ) -> Result<(), ArrayError>
Sourcepub const fn push_array_const<const TARRSIZE: usize>(
&mut self,
arr: [T; TARRSIZE],
)
pub const fn push_array_const<const TARRSIZE: usize>( &mut self, arr: [T; TARRSIZE], )
Pushes a raw array to the ConstFixedArray.
§Panics
Panics if the array is full. Should be consistent with ConstFixedArray::try_push_array_const.
Sourcepub const fn try_push_slice_const(
&mut self,
slice: &[T],
) -> Result<(), ArrayError>
pub const fn try_push_slice_const( &mut self, slice: &[T], ) -> Result<(), ArrayError>
Sourcepub const fn push_slice_const(&mut self, slice: &[T])
pub const fn push_slice_const(&mut self, slice: &[T])
Pushes a slice to the ConstFixedArray.
§Panics
Panics if the array is full. Should be consistent with ConstFixedArray::try_push_slice_const.
Sourcepub const fn try_push_const(&mut self, value: T) -> Result<(), ArrayError>
pub const fn try_push_const(&mut self, value: T) -> Result<(), ArrayError>
Sourcepub const fn push_const(&mut self, value: T)
pub const fn push_const(&mut self, value: T)
Pushes a single element to the ConstFixedArray.
§Panics
Panics if the array is full. Should be consistent with ConstFixedArray::try_push_const.
Sourcepub const fn try_pop_const(&mut self) -> Result<T, ArrayIsEmptyError>
pub const fn try_pop_const(&mut self) -> Result<T, ArrayIsEmptyError>
Removes an element from the top of the ConstFixedArray.
§Errors
Returns ArrayIsEmptyError when the array is empty.
Sourcepub const fn pop_const(&mut self) -> T
pub const fn pop_const(&mut self) -> T
Removes an element from the top of the ConstFixedArray.
§Panics
Panics if the array is empty. Should be consistent with ConstFixedArray::try_pop_const.
Sourcepub const fn clone_const(&self) -> Self
pub const fn clone_const(&self) -> Self
Clones the ConstFixedArray.
Sourcepub const unsafe fn as_raw_slice_const(&self) -> &[T; TSIZE]
pub const unsafe fn as_raw_slice_const(&self) -> &[T; TSIZE]
Returns the raw immutable reference to the underlying array.
§Safety
This function is unsafe because only the buffer up to Length
is guaranteed to be filled with a valid data.
Sourcepub const unsafe fn as_raw_slice_mut_const(&mut self) -> &mut [T; TSIZE]
pub const unsafe fn as_raw_slice_mut_const(&mut self) -> &mut [T; TSIZE]
Returns the raw mutable reference to the underlying array.
§Safety
This function is unsafe because only the buffer up to Length
is guaranteed to be filled with a valid data.
Sourcepub const fn drain(&mut self)
pub const fn drain(&mut self)
Drains the ConstFixedArray. This call sets the internal length of ConstFixedArray to 0,
making it effectively empty.