Skip to main content

ReactiveSharedArray

Struct ReactiveSharedArray 

Source
pub struct ReactiveSharedArray<T: Copy> { /* private fields */ }
Expand description

A reactive array backed by shared memory.

Reads from this array can trigger reactive subscriptions. The array is read-only from Rust’s perspective - writes come from the TypeScript side.

§Type Parameters

  • T: The element type (must be Copy for safe shared memory access)

Implementations§

Source§

impl<T: Copy> ReactiveSharedArray<T>

Source

pub unsafe fn new(ptr: *const T, len: usize, dirty: *const u8) -> Self

Create a new reactive shared array.

§Safety
  • ptr must point to valid shared memory with at least len * size_of::<T>() bytes
  • dirty must point to valid shared memory with at least len bytes
  • Both pointers must remain valid for the lifetime of this array
Source

pub unsafe fn from_context( ctx: &SharedBufferContext, byte_offset: usize, len: usize, ) -> Self

Create from a SharedBufferContext with byte offset.

§Safety
  • The offset must be properly aligned for type T
  • The region must not overlap with other mutable regions
Source

pub fn get(&self, index: usize) -> T

Get a value at the given index.

Source

pub fn is_dirty(&self, index: usize) -> bool

Check if an index is marked dirty.

Source

pub fn clear_dirty(&self, index: usize)

Clear the dirty flag for an index.

Source

pub fn dirty_indices(&self) -> Vec<usize>

Get all dirty indices.

Source

pub fn bump_version(&self)

Increment version (called when processing changes).

Source

pub fn version(&self) -> u32

Get current version.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub unsafe fn as_slice(&self) -> &[T]

Get a slice of the underlying data.

§Safety

The returned slice is only valid while the TypeScript side is not writing. Use only within a synchronized section.

Source

pub fn iter(&self) -> impl Iterator<Item = T> + '_

Iterate over all elements.

Trait Implementations§

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