Skip to main content

MatrixHandler

Struct MatrixHandler 

Source
pub struct MatrixHandler { /* private fields */ }
Expand description

The primary interface for interacting with an AtomicMatrix.

Owns the SHM mapping. Cannot be cloned — use [share()] to produce a SharedHandler for other threads.

See module documentation for the full abstraction layer diagram.

Implementations§

Source§

impl MatrixHandler

Source

pub fn share(&self) -> SharedHandler

Produces a lightweight SharedHandler that can be sent to other threads.

SharedHandler holds raw pointers into the SHM segment. This handler must outlive all shared handles derived from it — Rust cannot enforce this lifetime relationship automatically because SharedHandler uses raw pointers. Violating this contract is undefined behaviour.

Source

pub fn die(&self) -> Result<(), HandlerError>

Removes the SHM file from the system.

Should be called before the application exits to prevent the SHM file from persisting in /dev/shm/ across runs. This is an explicit, opt- in cleanup - if omitted, the file survives until the system reboots or it’s manually removed.

Existing mapping remains valid until the handlers are dropped; this only removes the filesystem entry, preventing new attachments.

Trait Implementations§

Source§

impl HandlerFunctions for MatrixHandler

Source§

fn base_ptr(&self) -> *const u8

Returns the SHM base pointer for this process’s mapping.
Source§

fn matrix(&self) -> &AtomicMatrix

Returns a reference to the underlying AtomicMatrix.
Source§

fn first_block_offset(&self) -> u32

Returns the offset of the first data block in the segment. Used by internals iterators as the physical chain walk start point.
Source§

fn segment_size(&self) -> u32

Returns the total segment size in bytes.
Source§

fn allocate<T>(&self) -> Result<Block<T>, HandlerError>

Allocates a block sized to hold T. Read more
Source§

fn allocate_raw(&self, size: u32) -> Result<RelativePtr<u8>, HandlerError>

Allocates a raw byte block of the given size. Read more
Source§

unsafe fn write<T>(&self, block: &mut Block<T>, value: T)

Writes a value of type T into an allocated block. Read more
Source§

unsafe fn read<'a, T>(&self, block: &Block<T>) -> &'a T

Reads a shared reference to T from an allocated block. Read more
Source§

unsafe fn read_mut<'a, T>(&self, block: &Block<T>) -> &'a mut T

Reads a mutable reference to T from an allocated block. Read more
Source§

fn free<T>(&self, block: Block<T>)

Frees a typed block. Read more
Source§

fn free_at(&self, header_offset: u32)

Frees a block by its header offset directly. Read more
Source§

fn set_state<T>(&self, block: &Block<T>, state: u32) -> Result<(), HandlerError>

Sets a user-defined lifecycle state on a block. Read more
Source§

fn get_state<T>(&self, block: &Block<T>, order: Ordering) -> u32

Returns the current state of a block. Read more
Source§

fn transition_state<T>( &self, block: &Block<T>, expected: u32, next: u32, success_order: Ordering, ) -> Result<u32, HandlerError>

Atomically transitions a block from one state to another. Read more
Source§

fn raw_matrix(&self) -> &AtomicMatrix

Returns a raw reference to the underlying AtomicMatrix. Read more
Source§

fn raw_base_ptr(&self) -> *const u8

Returns the raw SHM base pointer for this process’s mapping. Read more

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.