pub struct FixedArray<T, TAllocator>where
TAllocator: Allocator,{ /* private fields */ }Expand description
A fixed-capacity array. This type is similar to DynamicArray,
except its capacity is fixed at runtime, instead of compile time. Internally it keeps a pointer
to heap allocated data. That heap allocated data is never resized during the array’s lifetime.
This type does require an allocator. But if the size exceeds capacity it simply returns an error.
Implementations§
Source§impl<T, TAllocator> FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> FixedArray<T, TAllocator>where
TAllocator: Allocator,
Sourcepub fn with_capacity_and_allocator(
capacity: Length,
allocator: TAllocator,
) -> Result<Self, ArrayError>
pub fn with_capacity_and_allocator( capacity: Length, allocator: TAllocator, ) -> Result<Self, ArrayError>
Creates a new FixedArray with capacity and allocator.
This allocates memory only when capacity > 0.
§Errors
For details see ArrayError.
Sourcepub fn with_capacity(capacity: Length) -> Result<Self, ArrayError>where
TAllocator: Default,
pub fn with_capacity(capacity: Length) -> Result<Self, ArrayError>where
TAllocator: Default,
Creates a new FixedArray with capacity and the default allocator.
This allocates memory only when capacity > 0.
§Errors
For details see ArrayError.
Sourcepub fn with_factory<Factory: FnMut(usize) -> T>(
size: Length,
factory: Factory,
) -> Result<Self, ArrayError>where
TAllocator: Default,
pub fn with_factory<Factory: FnMut(usize) -> T>(
size: Length,
factory: Factory,
) -> Result<Self, ArrayError>where
TAllocator: Default,
Creates a new FixedArray with a given size, generated through a given factory.
This allocates memory only when size > 0.
§Errors
For details see ArrayError.
Sourcepub fn with_factory_and_allocator<Factory: FnMut(usize) -> T>(
size: Length,
factory: Factory,
allocator: TAllocator,
) -> Result<Self, ArrayError>
pub fn with_factory_and_allocator<Factory: FnMut(usize) -> T>( size: Length, factory: Factory, allocator: TAllocator, ) -> Result<Self, ArrayError>
Creates a new FixedArray with a given size, generated through a given factory,
with a custom allocator. This allocates memory only when size > 0.
§Errors
For details see ArrayError.
Sourcepub unsafe fn with_size_uninitialized(size: Length) -> Result<Self, ArrayError>where
TAllocator: Default,
pub unsafe fn with_size_uninitialized(size: Length) -> Result<Self, ArrayError>where
TAllocator: Default,
Creates a new FixedArray with a given size, but uninitialized.
§Safety
The underlying array is uninitialized and reading the data is UB, unless initialized first.
§Errors
For details see ArrayError.
Sourcepub unsafe fn with_size_and_allocator_uninitialized(
size: Length,
allocator: TAllocator,
) -> Result<Self, ArrayError>
pub unsafe fn with_size_and_allocator_uninitialized( size: Length, allocator: TAllocator, ) -> Result<Self, ArrayError>
Creates a new FixedArray with a given size and allocator, but uninitialized.
§Safety
The underlying array is uninitialized and reading the data is UB, unless initialized first.
§Errors
For details see ArrayError.
Trait Implementations§
Source§impl<T, TAllocator> AsMut<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> AsMut<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> AsRef<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> AsRef<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> Borrow<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Borrow<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> BorrowMut<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> BorrowMut<[T]> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§fn borrow_mut(&mut self) -> &mut [T]
fn borrow_mut(&mut self) -> &mut [T]
Source§impl<T, TAllocator> Clone for FixedArray<T, TAllocator>where
T: TryClone,
TAllocator: Allocator + TryClone,
impl<T, TAllocator> Clone for FixedArray<T, TAllocator>where
T: TryClone,
TAllocator: Allocator + TryClone,
Source§impl<T: Debug, TAllocator> Debug for FixedArray<T, TAllocator>where
TAllocator: Allocator + Debug,
impl<T: Debug, TAllocator> Debug for FixedArray<T, TAllocator>where
TAllocator: Allocator + Debug,
Source§impl<T, TAllocator> Drop for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Drop for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Eq for FixedArray<T, TAllocator>where
T: Eq,
TAllocator: Allocator,
Source§impl<T, TAllocator> Hash for FixedArray<T, TAllocator>where
T: Hash,
TAllocator: Allocator,
impl<T, TAllocator> Hash for FixedArray<T, TAllocator>where
T: Hash,
TAllocator: Allocator,
Source§impl<T, TAllocator> ImmutableArray<T> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> ImmutableArray<T> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> MutableArray<T> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> MutableArray<T> for FixedArray<T, TAllocator>where
TAllocator: Allocator,
Source§fn try_push_array<const TSIZE: usize>(
&mut self,
arr: [T; TSIZE],
) -> Result<(), ArrayError>
fn try_push_array<const TSIZE: usize>( &mut self, arr: [T; TSIZE], ) -> Result<(), ArrayError>
Source§fn try_push_slice(&mut self, slice: &[T]) -> Result<(), ArrayTryCloneError>where
T: TryClone,
fn try_push_slice(&mut self, slice: &[T]) -> Result<(), ArrayTryCloneError>where
T: TryClone,
Source§fn try_pop(&mut self) -> Result<T, ArrayIsEmptyError>
fn try_pop(&mut self) -> Result<T, ArrayIsEmptyError>
Source§fn try_push(&mut self, value: T) -> Result<(), ArrayError>
fn try_push(&mut self, value: T) -> Result<(), ArrayError>
Source§fn push_array<const TSIZE: usize>(&mut self, arr: [T; TSIZE])
fn push_array<const TSIZE: usize>(&mut self, arr: [T; TSIZE])
Source§fn push_slice(&mut self, slice: &[T])where
T: TryClone,
fn push_slice(&mut self, slice: &[T])where
T: TryClone,
Source§impl<T, TAllocator, Rhs> PartialEq<Rhs> for FixedArray<T, TAllocator>
impl<T, TAllocator, Rhs> PartialEq<Rhs> for FixedArray<T, TAllocator>
Source§impl<T, TAllocator> ReprC for FixedArray<T, TAllocator>where
T: ReprC,
TAllocator: Allocator,
impl<T, TAllocator> ReprC for FixedArray<T, TAllocator>where
T: ReprC,
TAllocator: Allocator,
impl<T, TAllocator> Send for FixedArray<T, TAllocator>
Source§impl<T: Serialize, TAllocator: Allocator> Serialize for FixedArray<T, TAllocator>
Available on crate feature serde only.
impl<T: Serialize, TAllocator: Allocator> Serialize for FixedArray<T, TAllocator>
serde only.