pub struct Array<T> { /* private fields */ }Expand description
Owns homogeneous, contiguous elements without bounds on the element type.
The transparent representation is an owning RawArray header, including
member destruction dispatch. Its elements have the concrete layout of T.
Nested arrays use Array<Array<T>>, not nested vectors.
Dropping an array destroys its elements exactly once in reverse index order,
then releases its allocation. Remaining elements also receive reverse-order
cleanup if a destructor unwinds; a second destructor panic during unwinding
aborts as usual. After Self::into_vec, the vector instead follows Rust’s
vector destruction behavior.
- Complexity: Destruction takes O(n) time and O(1) auxiliary space, excluding element destructor costs.
§Examples
use cel_runtime::Array;
let array = Array::from_vec(vec![String::from("leaf")]);
assert_eq!(array.as_slice(), &["leaf"]);Elements that are not Send cannot become transferable through an array:
use cel_runtime::Array;
use std::rc::Rc;
fn require_send<T: Send>() {}
require_send::<Array<Rc<()>>>();Elements that are not Sync cannot become shareable through an array:
use cel_runtime::Array;
use std::cell::Cell;
fn require_sync<T: Sync>() {}
require_sync::<Array<Cell<i32>>>();Implementations§
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn from_vec(values: Vec<T>) -> Array<T>
pub fn from_vec(values: Vec<T>) -> Array<T>
Takes ownership of a vector without moving elements or allocating.
- Postcondition: Contents, allocation pointer, length, and capacity are unchanged. Empty and zero-sized vectors retain their raw parts.
§Examples
use cel_runtime::Array;
let values = vec![3_i32, 5];
let pointer = values.as_ptr();
let array = Array::from_vec(values);
assert_eq!(array.as_slice().as_ptr(), pointer);Sourcepub fn into_vec(self) -> Vec<T>
pub fn into_vec(self) -> Vec<T>
Transfers ownership into a vector without moving elements or allocating.
- Postcondition: Contents, allocation pointer, length, and capacity are unchanged; this array runs no element destructors.
§Examples
use cel_runtime::Array;
let array = Array::from_vec(vec![3_i32, 5]);
let pointer = array.as_slice().as_ptr();
let values = array.into_vec();
assert_eq!(values.as_ptr(), pointer);
assert_eq!(values, [3, 5]);Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Borrows the contiguous elements without copying or allocating.
§Examples
use cel_runtime::Array;
let array = Array::from_vec(vec![3_i32, 5]);
let values: &[i32] = array.as_slice();
assert_eq!(values, &[3, 5]);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of initialized elements.
§Examples
use cel_runtime::Array;
assert_eq!(Array::from_vec(vec![3_i32, 5]).len(), 2);Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the allocation capacity in elements, as reported by the source vector.
Zero-sized elements retain the vector’s capacity of usize::MAX.
§Examples
use cel_runtime::Array;
let values = Vec::<i32>::with_capacity(8);
let capacity = values.capacity();
assert_eq!(Array::from_vec(values).capacity(), capacity);Trait Implementations§
Source§impl<T> Clone for Array<T>where
T: Clone,
impl<T> Clone for Array<T>where
T: Clone,
Source§fn clone(&self) -> Array<T>
fn clone(&self) -> Array<T>
Clones elements into a new array without sharing owned storage.
- Complexity: O(n) time and space, excluding element clone costs.
§Examples
use cel_runtime::Array;
let array = Array::from_vec(vec![String::from("leaf")]);
assert_eq!(array.clone().as_slice(), array.as_slice());1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for Array<T>where
T: Debug,
impl<T> Debug for Array<T>where
T: Debug,
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
Formats the array as Array([elements]) using element debug formatting.
- Complexity: O(n) element formatting calls, excluding element formatting costs and output storage.
§Errors
Returns an error if the formatter fails to write the representation.
§Examples
use cel_runtime::Array;
assert_eq!(format!("{:?}", Array::from_vec(vec![1_i32])), "Array([1])");Source§impl<T> PartialEq for Array<T>where
T: PartialEq,
impl<T> PartialEq for Array<T>where
T: PartialEq,
Source§fn eq(&self, other: &Array<T>) -> bool
fn eq(&self, other: &Array<T>) -> bool
Compares lengths and corresponding elements using element equality.
- Complexity: O(n) time in the worst case, excluding element comparison costs, and O(1) auxiliary space.
§Examples
use cel_runtime::Array;
assert_eq!(Array::from_vec(vec![1_i32]), Array::from_vec(vec![1_i32]));