Contiguous growable vector types that implement the Ruby
Array types are growable vectors with potentially heap-allocated contents.
The types in this crate can be passed by pointer over FFI.
Array types implement the mutating APIs in the Ruby
Array core class as
well as indexing and slicing APIs.
Arrayis based on
Vecfrom the Rust
alloccrate and standard library. This Spinoso array type is enabled by default.
SmallArrayis based on
SmallVecand implements the small vector optimization – small arrays are stored inline without a heap allocation. This Spinoso array type requires the small-array Cargo feature.
TinyArrayis based on
TinyVecand implements the small vector optimization – small arrays are stored inline without a heap allocation. This Spinoso array type requires the tiny-array Cargo feature.
This crate is
no_std with a required dependency on the
let ary: Array<i32> = Array::new();
let ary: Array<i32> = Array::from(vec![1, 2, 3, 4]); let ary2: Array<i32> = iter::repeat(1).take(10).collect();
push values onto the end of an array (which will
grow the array as needed):
let mut ary = Array::from(&[1, 2]); ary.push(3);
Popping values behaves similarly:
let mut ary = Array::from(&[1, 2]); assert_eq!(ary.pop(), Some(2));
let mut a = Array::from(&[1, 2, 3]); let three = a; a = a + 5;
Array vector types in this crate differ from
Vec in the Rust
by offering many specialized slicing and mutation APIs. For example, rather
than offering APIs like
Vec::splice, array types in
this crate offer specialized methods like
splice-like methods with
let mut a = Array::from(&[1, 2, 3]); a.unshift(0); assert_eq!(a, [0, 1, 2, 3]); let b = a.shift_n(10); assert_eq!(a, ); assert_eq!(b, [0, 1, 2, 3]);
Arrays in this crate do not expose panicking slicing operations (except for
IndexMut implementations). Instead of panicking,
slicing APIs operate until the end of the vector or return
Arrays on out of bounds access.
A wrapper around the decomposed parts of a
A contiguous growable array type based on
SmallVec<[T; INLINE_CAPACITY]> that implements the small vector
Vectors that implement the small vector optimization can store 8 elements inline without a heap allocation.