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
impl PackedArray
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn element_datatype(&self) -> DataType
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.
Sourcepub fn estimated_size(&self) -> usize
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).
Sourcepub fn into_values(self) -> Vec<Value>
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.
Sourcepub fn try_from_vec<T>(value: Vec<T>) -> Result<PackedArray, Vec<T>>where
T: 'static,
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.
Sourcepub fn try_into_vec<T>(self) -> Result<Vec<T>, PackedArray>where
T: 'static,
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
impl Clone for PackedArray
Source§fn clone(&self) -> PackedArray
fn clone(&self) -> PackedArray
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PackedArray
impl Debug for PackedArray
Source§impl From<PackedArray> for Value
impl From<PackedArray> for Value
Source§fn from(value: PackedArray) -> Value
fn from(value: PackedArray) -> Value
Source§impl PartialEq for PackedArray
impl PartialEq for PackedArray
impl StructuralPartialEq for PackedArray
Auto Trait Implementations§
impl Freeze for PackedArray
impl RefUnwindSafe for PackedArray
impl Send for PackedArray
impl Sync for PackedArray
impl Unpin for PackedArray
impl UnsafeUnpin for PackedArray
impl UnwindSafe for PackedArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.