Skip to main content

DynamicArray

Struct DynamicArray 

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

Source

pub fn new() -> Self
where TAllocator: Default,

Creates a new, empty DynamicArray.

Source

pub const fn with_allocator(allocator: TAllocator) -> Self

Creates a new, empty DynamicArray with an allocator.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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,

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T, TAllocator> AsRef<[T]> for DynamicArray<T, TAllocator>
where TAllocator: Allocator,

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, TAllocator> Borrow<[T]> for DynamicArray<T, TAllocator>
where TAllocator: Allocator,

Source§

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more
Source§

impl<T, TAllocator> BorrowMut<[T]> for DynamicArray<T, TAllocator>
where TAllocator: Allocator,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T, TAllocator> Clone for DynamicArray<T, TAllocator>
where T: TryClone + Clone, TAllocator: Allocator + TryClone + Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, TAllocator> Debug for DynamicArray<T, TAllocator>
where TAllocator: Allocator + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, TAllocator> Default for DynamicArray<T, TAllocator>
where TAllocator: Allocator + Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T: Deserialize<'de>, TAllocator: Allocator + Default> Deserialize<'de> for DynamicArray<T, TAllocator>

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T, TAllocator> Drop for DynamicArray<T, TAllocator>
where TAllocator: Allocator,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

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,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, TAllocator> ImmutableArray<T> for DynamicArray<T, TAllocator>
where TAllocator: Allocator,

Source§

fn length(&self) -> Length

Returns array’s length as [Length].
Source§

fn capacity(&self) -> Length

Returns the current capacity for holding items in the array.
Source§

fn is_empty(&self) -> bool

Returns true if array is empty, false otherwise. Should be consistent with self.length() == Length::ZERO check.
Source§

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>

Tries to push raw array to the array. Read more
Source§

fn try_push_slice(&mut self, slice: &[T]) -> Result<(), ArrayTryCloneError>
where T: TryClone,

Tries to push slice to the array. This method requires Clone trait on T. Read more
Source§

fn try_pop(&mut self) -> Result<T, ArrayIsEmptyError>

Removes element from the top of the array. Read more
Source§

fn pop(&mut self) -> T

Removes element from the top of the array. Read more
Source§

fn try_push(&mut self, value: T) -> Result<(), ArrayError>

Pushes a single element to the array. Read more
Source§

fn push_array<const TSIZE: usize>(&mut self, arr: [T; TSIZE])

Pushes raw array to the array. Read more
Source§

fn push_slice(&mut self, slice: &[T])
where T: TryClone,

Pushes raw slice to the array. This method requires Clone trait on T. Read more
Source§

fn push(&mut self, value: T)

Pushes a single element to the array. Read more
Source§

impl<T, TAllocator, Rhs> PartialEq<Rhs> for DynamicArray<T, TAllocator>
where T: PartialEq, TAllocator: Allocator, Rhs: AsRef<[T]>,

Source§

fn eq(&self, other: &Rhs) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, TAllocator> ReprC for DynamicArray<T, TAllocator>
where T: ReprC, TAllocator: Allocator,

Source§

const CHECK: ()

This field is used for const checks only.
Source§

impl<T: Serialize, TAllocator: Allocator> Serialize for DynamicArray<T, TAllocator>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, TAllocator> TryClone for DynamicArray<T, TAllocator>
where T: TryClone, TAllocator: Allocator + TryClone,

Source§

type Error = ArrayTryCloneError

Source§

fn try_clone(&self) -> Result<Self, Self::Error>

Tries to clone the type. Read more

Auto Trait Implementations§

§

impl<T, TAllocator> Freeze for DynamicArray<T, TAllocator>
where TAllocator: Freeze,

§

impl<T, TAllocator> RefUnwindSafe for DynamicArray<T, TAllocator>
where TAllocator: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, TAllocator> Send for DynamicArray<T, TAllocator>
where T: Send, TAllocator: Send,

§

impl<T, TAllocator> Sync for DynamicArray<T, TAllocator>
where T: Sync, TAllocator: Sync,

§

impl<T, TAllocator> Unpin for DynamicArray<T, TAllocator>
where TAllocator: Unpin, T: Unpin,

§

impl<T, TAllocator> UnsafeUnpin for DynamicArray<T, TAllocator>
where TAllocator: UnsafeUnpin,

§

impl<T, TAllocator> UnwindSafe for DynamicArray<T, TAllocator>
where TAllocator: UnwindSafe, T: RefUnwindSafe + 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.