pub struct DynamicArray<T, TAllocator>where
TAllocator: Allocator,{ /* private fields */ }Expand description
A #[repr(C)] variant of the standard vec struct.
Functionally similar, and implements [ReprC] for T: ReprC. However,
unlike vec this struct multiplies capacity by 3/2 when resizing is
needed.
Implementations§
Source§impl<T, TAllocator> DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> DynamicArray<T, TAllocator>where
TAllocator: Allocator,
Sourcepub fn new() -> Selfwhere
TAllocator: Default,
pub fn new() -> Selfwhere
TAllocator: Default,
Creates a new, empty DynamicArray.
Sourcepub const fn with_allocator(allocator: TAllocator) -> Self
pub const fn with_allocator(allocator: TAllocator) -> Self
Creates a new, empty DynamicArray with an 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 DynamicArray 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 DynamicArray 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 DynamicArray with a given size, generated through a given factory.
This allocates memory only when size > 0.
§Notes
This method is functionally equivalent to initializing an empty vector and running
factory one by one in a loop, and passing it to
push. This way, however, is more efficient,
even if you preallocate the vector with capacity. Because this method gives the
compiler an opportunity to vectorize the construction, unlike sequential
push calls.
§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 DynamicArray with a given size, generated through a given factory,
with a custom allocator. This allocates memory only when size > 0.
§Notes
This method is functionally equivalent to initializing an empty vector and running
factory one by one in a loop, and passing it to
push. This way, however, is more efficient,
even if you preallocate the vector with capacity. Because this method gives the
compiler an opportunity to vectorize the construction, unlike sequential
push calls.
§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 DynamicArray 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 DynamicArray 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 DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> AsMut<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> AsRef<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> AsRef<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> Borrow<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Borrow<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> BorrowMut<[T]> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> BorrowMut<[T]> for DynamicArray<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 DynamicArray<T, TAllocator>
impl<T, TAllocator> Clone for DynamicArray<T, TAllocator>
Source§impl<T: Debug, TAllocator> Debug for DynamicArray<T, TAllocator>where
TAllocator: Allocator + Debug,
impl<T: Debug, TAllocator> Debug for DynamicArray<T, TAllocator>where
TAllocator: Allocator + Debug,
Source§impl<T, TAllocator> Default for DynamicArray<T, TAllocator>where
TAllocator: Allocator + Default,
impl<T, TAllocator> Default for DynamicArray<T, TAllocator>where
TAllocator: Allocator + Default,
Source§impl<'de, T: Deserialize<'de>, TAllocator: Allocator + Default> Deserialize<'de> for DynamicArray<T, TAllocator>
Available on crate feature serde only.
impl<'de, T: Deserialize<'de>, TAllocator: Allocator + Default> Deserialize<'de> for DynamicArray<T, TAllocator>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T, TAllocator> Drop for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Drop for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> Eq for DynamicArray<T, TAllocator>where
T: Eq,
TAllocator: Allocator,
Source§impl<T, TAllocator> Hash for DynamicArray<T, TAllocator>where
T: Hash,
TAllocator: Allocator,
impl<T, TAllocator> Hash for DynamicArray<T, TAllocator>where
T: Hash,
TAllocator: Allocator,
Source§impl<T, TAllocator> ImmutableArray<T> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> ImmutableArray<T> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
Source§impl<T, TAllocator> MutableArray<T> for DynamicArray<T, TAllocator>where
TAllocator: Allocator,
impl<T, TAllocator> MutableArray<T> for DynamicArray<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 DynamicArray<T, TAllocator>
impl<T, TAllocator, Rhs> PartialEq<Rhs> for DynamicArray<T, TAllocator>
Source§impl<T, TAllocator> ReprC for DynamicArray<T, TAllocator>where
T: ReprC,
TAllocator: Allocator,
impl<T, TAllocator> ReprC for DynamicArray<T, TAllocator>where
T: ReprC,
TAllocator: Allocator,
Source§impl<T: Serialize, TAllocator: Allocator> Serialize for DynamicArray<T, TAllocator>
Available on crate feature serde only.
impl<T: Serialize, TAllocator: Allocator> Serialize for DynamicArray<T, TAllocator>
serde only.