Skip to main content

Array

Struct Array 

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

Source

pub fn from_vec(values: Vec<T>) -> Self

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);
Source

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]);
Source

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]);
Source

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);
Source

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);
Source

pub fn is_empty(&self) -> bool

Returns whether the array contains no elements.

§Examples
use cel_runtime::Array;
assert!(Array::from_vec(Vec::<i32>::new()).is_empty());

Trait Implementations§

Source§

impl<T: Clone> Clone for Array<T>

Source§

fn clone(&self) -> Self

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)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Array<T>

Source§

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

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> PartialEq for Array<T>

Source§

fn eq(&self, other: &Self) -> 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]));
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: Send> Send for Array<T>

Source§

impl<T: Sync> Sync for Array<T>

Auto Trait Implementations§

§

impl<T> Freeze for Array<T>

§

impl<T> RefUnwindSafe for Array<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Array<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Array<T>

§

impl<T> UnwindSafe for Array<T>
where T: 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> 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> Same for T

Source§

type Output = T

Should always be Self
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.