LinearMemory

Trait LinearMemory 

Source
pub trait LinearMemory {
    // Required methods
    fn new(size: usize) -> Self;
    fn size(&self) -> usize;
    fn as_slice(&self) -> &[u8] ;
    fn as_mut_slice(&mut self) -> &mut [u8] ;
    unsafe fn read<BLOCK: Copy>(&self, from: usize) -> BLOCK;
    unsafe fn read_unaligned<BLOCK: Copy>(&self, from: usize) -> BLOCK;
    unsafe fn write<BLOCK: Copy>(&mut self, start: usize, values: BLOCK);
    unsafe fn write_unaligned<BLOCK: Copy>(
        &mut self,
        start: usize,
        values: BLOCK,
    );
    unsafe fn swap<BLOCK: Copy>(&mut self, start: usize, values: &mut BLOCK);
    unsafe fn copy_nonoverlapping<T: Copy>(&mut self, to: usize, data: &[T]);
    unsafe fn get_aligned_slice<T: Copy>(
        &self,
        start: usize,
        len: usize,
    ) -> &[T];

    // Provided method
    fn fill_zero(&mut self) { ... }
}
Expand description

API for any memory implementation that allocates a contiguous region of memory.

Required Methods§

Source

fn new(size: usize) -> Self

Create instance of Self with size bytes.

Source

fn size(&self) -> usize

Allocated size of the memory in bytes.

Source

fn as_slice(&self) -> &[u8]

Returns the entire memory as a raw byte slice.

Source

fn as_mut_slice(&mut self) -> &mut [u8]

Returns the entire memory as a raw byte slice.

Source

unsafe fn read<BLOCK: Copy>(&self, from: usize) -> BLOCK

Read BLOCK from self at from address without moving it.

Panics or segfaults if from..from + size_of::<BLOCK>() is out of bounds.

§Safety
  • BLOCK should be “plain old data” (see Pod). We do not add a trait bound due to Plonky3 types not implementing the trait.
  • See core::ptr::read for similar considerations.
  • Memory at from must be properly aligned for BLOCK. Use Self::read_unaligned if alignment is not guaranteed.
Source

unsafe fn read_unaligned<BLOCK: Copy>(&self, from: usize) -> BLOCK

Read BLOCK from self at from address without moving it. Same as Self::read except that it does not require alignment.

Panics or segfaults if from..from + size_of::<BLOCK>() is out of bounds.

§Safety
  • BLOCK should be “plain old data” (see Pod). We do not add a trait bound due to Plonky3 types not implementing the trait.
  • See core::ptr::read for similar considerations.
Source

unsafe fn write<BLOCK: Copy>(&mut self, start: usize, values: BLOCK)

Write BLOCK to self at start address without reading the old value. Does not drop values. Semantically, values is moved into the location pointed to by start.

Panics or segfaults if start..start + size_of::<BLOCK>() is out of bounds.

§Safety
Source

unsafe fn write_unaligned<BLOCK: Copy>(&mut self, start: usize, values: BLOCK)

Write BLOCK to self at start address without reading the old value. Does not drop values. Semantically, values is moved into the location pointed to by start. Same as Self::write but without alignment requirement.

Panics or segfaults if start..start + size_of::<BLOCK>() is out of bounds.

§Safety
Source

unsafe fn swap<BLOCK: Copy>(&mut self, start: usize, values: &mut BLOCK)

Swaps values with memory at start..start + size_of::<BLOCK>().

Panics or segfaults if start..start + size_of::<BLOCK>() is out of bounds.

§Safety
  • BLOCK should be “plain old data” (see Pod). We do not add a trait bound due to Plonky3 types not implementing the trait.
  • Memory at start must be properly aligned for BLOCK.
  • The data in values should not overlap with memory in self.
Source

unsafe fn copy_nonoverlapping<T: Copy>(&mut self, to: usize, data: &[T])

Copies data into memory at to address.

Panics or segfaults if to..to + size_of_val(data) is out of bounds.

§Safety
  • T should be “plain old data” (see Pod). We do not add a trait bound due to Plonky3 types not implementing the trait.
  • The underlying memory of data should not overlap with self.
  • The starting pointer of self should be aligned to T.
  • The memory pointer at to should be aligned to T.
Source

unsafe fn get_aligned_slice<T: Copy>(&self, start: usize, len: usize) -> &[T]

Returns a slice &[T] for the memory region start..start + len.

Panics or segfaults if start..start + len * size_of::<T>() is out of bounds.

§Safety
  • T should be “plain old data” (see Pod). We do not add a trait bound due to Plonky3 types not implementing the trait.
  • Memory at start must be properly aligned for T.

Provided Methods§

Source

fn fill_zero(&mut self)

Fill the memory with zeros.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§