Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

A zero-allocation reader for the communication channel.

The Reader provides methods to read primitive values and arrays from a shared memory buffer. It maintains proper alignment for different data types and tracks the current offset position.

§Examples

let mut storage = vec![0u64; 1024];
let mut reader = Reader::from(&mut storage);

let value = reader.read_u32();
let pi = reader.read_f64();

let array = reader.read_array_i32();

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn from(storage: &'a mut [u64]) -> Self

Creates a new Reader from a mutable slice of u64 storage.

The storage must be 8-byte aligned and will be reinterpreted as different primitive types as needed.

§Arguments
  • storage - A mutable slice of u64 values to use as the backing buffer
§Returns

A new Reader instance ready to read data.

Source

pub fn reset(&mut self)

Resets the reader to the beginning of the buffer.

This allows reusing the same buffer for multiple read operations.

Source

pub fn read_u8(&self) -> u8

Reads a u8 value from the channel.

§Returns

The u8 value read from the channel.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_array_u8(&self) -> &[u8]

Reads a u8 array from the channel with length prefix.

First reads the array length as u32, then reads that many elements.

§Returns

A slice of u8 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_elements_u8(&self, length: u32) -> &[u8]

Reads u8 array elements from the channel without length prefix.

§Arguments
  • length - The number of elements to read
§Returns

A slice of u8 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_u32(&self) -> u32

Reads a u32 value from the channel.

§Returns

The u32 value read from the channel.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_array_u32(&self) -> &[u32]

Reads a u32 array from the channel with length prefix.

First reads the array length as u32, then reads that many elements.

§Returns

A slice of u32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_elements_u32(&self, length: u32) -> &[u32]

Reads u32 array elements from the channel without length prefix.

§Arguments
  • length - The number of elements to read
§Returns

A slice of u32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_i32(&self) -> i32

Reads a i32 value from the channel.

§Returns

The i32 value read from the channel.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_array_i32(&self) -> &[i32]

Reads a i32 array from the channel with length prefix.

First reads the array length as u32, then reads that many elements.

§Returns

A slice of i32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_elements_i32(&self, length: u32) -> &[i32]

Reads i32 array elements from the channel without length prefix.

§Arguments
  • length - The number of elements to read
§Returns

A slice of i32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_f32(&self) -> f32

Reads a f32 value from the channel.

§Returns

The f32 value read from the channel.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_array_f32(&self) -> &[f32]

Reads a f32 array from the channel with length prefix.

First reads the array length as u32, then reads that many elements.

§Returns

A slice of f32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_elements_f32(&self, length: u32) -> &[f32]

Reads f32 array elements from the channel without length prefix.

§Arguments
  • length - The number of elements to read
§Returns

A slice of f32 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_f64(&self) -> f64

Reads a f64 value from the channel.

§Returns

The f64 value read from the channel.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_array_f64(&self) -> &[f64]

Reads a f64 array from the channel with length prefix.

First reads the array length as u32, then reads that many elements.

§Returns

A slice of f64 values.

§Panics

Panics if the channel buffer would overflow.

Source

pub fn read_elements_f64(&self, length: u32) -> &[f64]

Reads f64 array elements from the channel without length prefix.

§Arguments
  • length - The number of elements to read
§Returns

A slice of f64 values.

§Panics

Panics if the channel buffer would overflow.

Auto Trait Implementations§

§

impl<'a> !Freeze for Reader<'a>

§

impl<'a> !RefUnwindSafe for Reader<'a>

§

impl<'a> !Sync for Reader<'a>

§

impl<'a> !UnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

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.