Skip to main content

TypedArray

Struct TypedArray 

Source
#[repr(C)]
pub struct TypedArray<T> { pub header: HeapHeader, pub data: *mut T, pub len: u32, pub cap: u32, }
Expand description

Typed contiguous array with refcounted header.

Allocated on the heap via raw allocator. The data pointer points to a separate allocation holding cap elements of type T.

Fields§

§header: HeapHeader

8-byte v2 heap header (refcount at offset 0).

§data: *mut T

Pointer to contiguous T buffer.

§len: u32

Number of elements currently stored.

§cap: u32

Allocated capacity in number of elements.

Implementations§

Source§

impl<T: Copy> TypedArray<T>

Source

pub fn new() -> *mut Self

Allocate a new empty TypedArray with capacity 0.

Returns a raw pointer to the heap-allocated array. The caller is responsible for eventually calling drop_array to free it.

Source

pub fn with_capacity(cap: u32) -> *mut Self

Allocate a new TypedArray with the given capacity.

Returns a raw pointer to the heap-allocated array.

Source

pub fn from_slice(slice: &[T]) -> *mut Self

Create a TypedArray from a slice, copying all elements.

Source

pub unsafe fn get(this: *const Self, index: u32) -> Option<T>

Get an element by index, returning None if out of bounds.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn get_unchecked(this: *const Self, index: u32) -> T

Get an element by index without bounds checking.

§Safety

this must point to a valid, live TypedArray<T>, and index must be less than the array’s length.

Source

pub unsafe fn set(this: *mut Self, index: u32, val: T)

Set an element by index. Panics if out of bounds.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn push(this: *mut Self, val: T)

Push an element, growing the buffer if necessary (doubling strategy).

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn pop(this: *mut Self) -> Option<T>

Pop the last element, returning None if empty.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn len(this: *const Self) -> u32

Get the number of elements.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn capacity(this: *const Self) -> u32

Get the allocated capacity.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn is_empty(this: *const Self) -> bool

Check if the array is empty.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn as_slice<'a>(this: *const Self) -> &'a [T]

Get the elements as a slice.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn as_mut_slice<'a>(this: *mut Self) -> &'a mut [T]

Get the elements as a mutable slice.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn drop_array(ptr: *mut Self)

Deallocate the array and its data buffer.

§Safety

ptr must point to a TypedArray<T> that was allocated by this module. After calling this, ptr is invalid.

Source§

impl<T: HeapElement> TypedArray<*const T>

Heap-element-aware drop dispatch for TypedArray<*const T> where T: HeapElement.

Per ADR-006 §2.7.24 Q25.A SUPERSEDED + R20 S2-prime audit deliverable (b) §4.1.B decision: drop_array_heap walks the element buffer and calls T::release_elem(elem_ptr) for each stored pointer, then frees the data buffer + the TypedArray struct itself. Per-T dispatch is monomorphized at compile time via the HeapElement trait — no runtime NativeKind probe.

Pairs with the POD-element drop_array for T: Copy (above). Callers pick at compile time based on whether the element type is POD (plain scalar like f64/i64) or HeapHeader-equipped (*const StringObj / *const DecimalObj / …).

Source

pub unsafe fn drop_array_heap(ptr: *mut Self)

Deallocate the array, releasing per-element shares via T::release_elem, then freeing the data buffer + the struct.

§Safety

ptr must point to a TypedArray<*const T> that was allocated by this module. Each stored *const T must be a valid pointer to a live T allocation with at least one refcount share owned by this array. After this call, ptr is invalid.

Source§

impl<T> TypedArray<T>

Source

pub fn new_generic() -> *mut Self

Allocate a new empty TypedArray with capacity 0 — non-Copy variant.

Returns a raw pointer to the heap-allocated array. The caller is responsible for eventually freeing it via HashMapValueElem:: release_typed_array (for HashMapData<V> value buffers) or the equivalent per-T release path.

Source

pub fn with_capacity_generic(cap: u32) -> *mut Self

Allocate a new TypedArray with the given capacity — non-Copy variant.

Returns a raw pointer to the heap-allocated array. No elements are written; the data buffer is uninitialized memory of length cap * size_of::<T>().

Source

pub unsafe fn len_generic(this: *const Self) -> u32

Get the number of elements — non-Copy variant.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn capacity_generic(this: *const Self) -> u32

Get the allocated capacity — non-Copy variant.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn is_empty_generic(this: *const Self) -> bool

Check if the array is empty — non-Copy variant.

§Safety

this must point to a valid, live TypedArray<T>.

Source

pub unsafe fn as_slice_generic<'a>(this: *const Self) -> &'a [T]

Get the elements as a slice — non-Copy variant.

§Safety

this must point to a valid, live TypedArray<T>.

Auto Trait Implementations§

§

impl<T> !Freeze for TypedArray<T>

§

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

§

impl<T> !Send for TypedArray<T>

§

impl<T> !Sync for TypedArray<T>

§

impl<T> Unpin for TypedArray<T>

§

impl<T> UnsafeUnpin for TypedArray<T>

§

impl<T> UnwindSafe for TypedArray<T>
where T: RefUnwindSafe,

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> 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, 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.