pub trait Array:
Default
+ Len
+ Reserve
+ Filled<Self::Item>
+ Trunc
+ Indexed<Self::Item>
+ Extend<Self::Item>
+ FromIterator<Self::Item>
+ IntoIterator<Item = Self::Item>
+ Deref<Target = [Self::Item]>
+ DerefMut {
type Item;
}Expand description
A generalization of std::vec::Vec
§Provided implementations
§Why tinyvec::ArrayVec?
The performance of heapless and arrayvec’s Extend implementations
are notably worse than tinyvec. (see toad-msg/benches/collections.rs)
tinyvec also has the added bonus of being 100% unsafe-code-free.
§Definition of an Array
The Array trait is automatically implemented for ordered indexed collections with a non-fixed number of elements which are contiguous in memory.
This translates to the trait requirements:
- Must have an empty (
Default) value - Must allow populating every element with a value (
Filled) - Must allow dropping every element after a given index (
Trunc) - Must allow mutably appending one or more elements (
Extend) - Must be creatable from an iterator (
FromIterator) - Must allow iterating over owned elements (
IntoIterator) - Must be dereferenceable to readonly and mutable slices (
Deref,DerefMut) - Must allow getting the runtime length (
Len) - May have a hard limit on number of elements (
Len) - May allow creating an instance with maximum length and a given filler value (
Filled) - May allow pre-allocating space for a specific number of elements (
Reserve)
Required Associated Types§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.