Skip to main content

PackedArray

Enum PackedArray 

Source
pub enum PackedArray {
Show 15 variants I8(Arc<Vec<i8>>), I16(Arc<Vec<i16>>), I32(Arc<Vec<i32>>), I64(Arc<Vec<i64>>), I128(Arc<Vec<i128>>), U8(Arc<Vec<u8>>), U16(Arc<Vec<u16>>), U32(Arc<Vec<u32>>), U64(Arc<Vec<u64>>), U128(Arc<Vec<u128>>), F32(Arc<Vec<f32>>), F64(Arc<Vec<f64>>), Bool(Arc<Vec<bool>>), Byte(Arc<Vec<u8>>), Char(Arc<Vec<char>>),
}
Expand description

A contiguous, Arc-shared array of one primitive scalar type.

Backs Value::Packed: the packed counterpart of Value::Vec(Vec<Value>) for a homogeneous scalar array. Storage is size_of::<T>() bytes per element instead of one full Value enum instance (~24-32 bytes) per element.

Wraps Arc<Vec<T>> rather than Arc<[T]>: converting an existing Vec<T> into Arc<Vec<T>> (Arc::new) never touches the element data — only a small new allocation for the refcount header, with the Vec’s own {ptr,len,cap} moved into it. Arc<[T]> looks similar but is a dynamically-sized type that must sit directly beside its refcount header in one allocation, so Arc<[T]>::from(vec) always reallocates and copies every element (verified empirically). The trade is that a Vec built with spare capacity (e.g. via repeated push) keeps that slack for the Arc’s lifetime instead of being trimmed — bounded (typically ≤2x from geometric growth) and dwarfed by the per-element Value overhead this type avoids in the first place. See ticket #116.

Variants§

§

I8(Arc<Vec<i8>>)

§

I16(Arc<Vec<i16>>)

§

I32(Arc<Vec<i32>>)

§

I64(Arc<Vec<i64>>)

§

I128(Arc<Vec<i128>>)

§

U8(Arc<Vec<u8>>)

§

U16(Arc<Vec<u16>>)

§

U32(Arc<Vec<u32>>)

§

U64(Arc<Vec<u64>>)

§

U128(Arc<Vec<u128>>)

§

F32(Arc<Vec<f32>>)

§

F64(Arc<Vec<f64>>)

§

Bool(Arc<Vec<bool>>)

§

Byte(Arc<Vec<u8>>)

Distinct from U8, mirroring Value::Byte vs Value::U8: this is the packed form of the mel byte type specifically, not of generic 8-bit unsigned integers.

§

Char(Arc<Vec<char>>)

Implementations§

Source§

impl PackedArray

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn element_datatype(&self) -> DataType

The logical element type, used by Value::datatype() to report Vec(element) regardless of whether the value happens to be packed or boxed — Packed is purely an internal representation choice, invisible to the mel type system.

Source

pub fn estimated_size(&self) -> usize

Rough memory footprint of the array’s content, in bytes: element count times element width, with no per-element Value overhead (see Value::estimated_size).

Source

pub fn into_values(self) -> Vec<Value>

Expands into one Value per element. This is the correctness fallback for contexts that genuinely need the fully-boxed representation (e.g. Display) — it reintroduces exactly the per-element overhead Packed exists to avoid. Prefer try_into_vec/GetData<Arc<Vec<T>>> wherever the target type is known.

Source

pub fn try_from_vec<T>(value: Vec<T>) -> Result<PackedArray, Vec<T>>
where T: 'static,

Attempts to pack a Vec<T> using only T: 'static — no trait bound naming the packable types is needed, since the check happens at runtime via Any. Returns the vec back unchanged if T isn’t one of the packable primitives, so the caller can fall back to the ordinary boxed representation. Never produces Byte: a Vec<u8> is ambiguous between “bytes” and “generic small integers”, so this always resolves it to U8, exactly like Value::from(u8) never producing Value::Byte on its own.

Source

pub fn try_into_vec<T>(self) -> Result<Vec<T>, PackedArray>
where T: 'static,

Attempts to extract a Vec<T> directly, with no Value ever created along the way — the fast counterpart to into_values() followed by per-element GetData::<T>::try_data. If the array’s element type doesn’t already match T exactly (via Any), the original PackedArray is handed back unchanged.

Only makes one copy: Arc::try_unwrap succeeds for free when this is the sole reference to the array (the common case for a value that just arrived off a channel); it falls back to cloning only when the array is still shared elsewhere.

Trait Implementations§

Source§

impl Clone for PackedArray

Source§

fn clone(&self) -> PackedArray

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 Debug for PackedArray

Source§

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

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

impl From<Arc<Vec<bool>>> for PackedArray

Source§

fn from(value: Arc<Vec<bool>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<char>>> for PackedArray

Source§

fn from(value: Arc<Vec<char>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<f32>>> for PackedArray

Source§

fn from(value: Arc<Vec<f32>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<f64>>> for PackedArray

Source§

fn from(value: Arc<Vec<f64>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<i8>>> for PackedArray

Source§

fn from(value: Arc<Vec<i8>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<i16>>> for PackedArray

Source§

fn from(value: Arc<Vec<i16>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<i32>>> for PackedArray

Source§

fn from(value: Arc<Vec<i32>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<i64>>> for PackedArray

Source§

fn from(value: Arc<Vec<i64>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<i128>>> for PackedArray

Source§

fn from(value: Arc<Vec<i128>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<u8>>> for PackedArray

Source§

fn from(value: Arc<Vec<u8>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<u16>>> for PackedArray

Source§

fn from(value: Arc<Vec<u16>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<u32>>> for PackedArray

Source§

fn from(value: Arc<Vec<u32>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<u64>>> for PackedArray

Source§

fn from(value: Arc<Vec<u64>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Arc<Vec<u128>>> for PackedArray

Source§

fn from(value: Arc<Vec<u128>>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<PackedArray> for Value

Source§

fn from(value: PackedArray) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for PackedArray

Source§

fn from(value: Vec<bool>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<char>> for PackedArray

Source§

fn from(value: Vec<char>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<f32>> for PackedArray

Source§

fn from(value: Vec<f32>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for PackedArray

Source§

fn from(value: Vec<f64>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<i8>> for PackedArray

Source§

fn from(value: Vec<i8>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<i16>> for PackedArray

Source§

fn from(value: Vec<i16>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<i32>> for PackedArray

Source§

fn from(value: Vec<i32>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<i64>> for PackedArray

Source§

fn from(value: Vec<i64>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<i128>> for PackedArray

Source§

fn from(value: Vec<i128>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for PackedArray

Source§

fn from(value: Vec<u8>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<u16>> for PackedArray

Source§

fn from(value: Vec<u16>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<u32>> for PackedArray

Source§

fn from(value: Vec<u32>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<u64>> for PackedArray

Source§

fn from(value: Vec<u64>) -> PackedArray

Converts to this type from the input type.
Source§

impl From<Vec<u128>> for PackedArray

Source§

fn from(value: Vec<u128>) -> PackedArray

Converts to this type from the input type.
Source§

impl GetData<PackedArray> for Value

Source§

impl PartialEq for PackedArray

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PackedArray

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> PartialEquality for T
where T: PartialEq,

Source§

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

Source§

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

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.