Skip to main content

ConstFixedArray

Struct ConstFixedArray 

Source
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>

Source

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].

Source

pub const fn length(&self) -> Length

Returns the length of the ConstFixedArray.

Source

pub const fn is_empty(&self) -> bool

Source

pub const fn capacity(&self) -> Length

Returns the capacity of the ConstFixedArray. This is TSIZE as [Length].

Source

pub const fn as_slice_const(&self) -> &[T]

Returns the ConstFixedArray as immutable slice.

Source

pub const fn as_slice_mut_const(&mut self) -> &mut [T]

Returns the ConstFixedArray as mutable slice.

Source

pub const fn try_push_array_const<const TARRSIZE: usize>( &mut self, arr: [T; TARRSIZE], ) -> Result<(), ArrayError>

Pushes a raw array to the ConstFixedArray.

§Errors

For errors see ArrayError.

Source

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.

Source

pub const fn try_push_slice_const( &mut self, slice: &[T], ) -> Result<(), ArrayError>

Pushes a slice to the ConstFixedArray.

§Errors

For errors see ArrayError.

Source

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.

Source

pub const fn try_push_const(&mut self, value: T) -> Result<(), ArrayError>

Pushes a single element to the ConstFixedArray.

§Errors

For errors see ArrayError.

Source

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.

Source

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.

Source

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.

Source

pub const fn clone_const(&self) -> Self

Clones the ConstFixedArray.

Source

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.

Source

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.

Source

pub const fn drain(&mut self)

Drains the ConstFixedArray. This call sets the internal length of ConstFixedArray to 0, making it effectively empty.

Trait Implementations§

Source§

impl<const TSIZE: usize, T: ReprC + Sized + Copy> ReprC for ConstFixedArray<TSIZE, T>

Source§

const CHECK: ()

This field is used for const checks only.

Auto Trait Implementations§

§

impl<const TSIZE: usize, T> Freeze for ConstFixedArray<TSIZE, T>
where T: Freeze,

§

impl<const TSIZE: usize, T> RefUnwindSafe for ConstFixedArray<TSIZE, T>
where T: RefUnwindSafe,

§

impl<const TSIZE: usize, T> Send for ConstFixedArray<TSIZE, T>
where T: Send,

§

impl<const TSIZE: usize, T> Sync for ConstFixedArray<TSIZE, T>
where T: Sync,

§

impl<const TSIZE: usize, T> Unpin for ConstFixedArray<TSIZE, T>
where T: Unpin,

§

impl<const TSIZE: usize, T> UnsafeUnpin for ConstFixedArray<TSIZE, T>
where T: UnsafeUnpin,

§

impl<const TSIZE: usize, T> UnwindSafe for ConstFixedArray<TSIZE, T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.