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§
Sourcefn as_mut_slice(&mut self) -> &mut [u8] ⓘ
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns the entire memory as a raw byte slice.
Sourceunsafe fn read<BLOCK: Copy>(&self, from: usize) -> BLOCK
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
BLOCKshould be “plain old data” (seePod). We do not add a trait bound due to Plonky3 types not implementing the trait.- See
core::ptr::readfor similar considerations. - Memory at
frommust be properly aligned forBLOCK. UseSelf::read_unalignedif alignment is not guaranteed.
Sourceunsafe fn read_unaligned<BLOCK: Copy>(&self, from: usize) -> BLOCK
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
BLOCKshould be “plain old data” (seePod). We do not add a trait bound due to Plonky3 types not implementing the trait.- See
core::ptr::readfor similar considerations.
Sourceunsafe fn write<BLOCK: Copy>(&mut self, start: usize, values: BLOCK)
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
- See
core::ptr::writefor similar considerations. - Memory at
startmust be properly aligned forBLOCK. UseSelf::write_unalignedif alignment is not guaranteed.
Sourceunsafe fn write_unaligned<BLOCK: Copy>(&mut self, start: usize, values: BLOCK)
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
- See
core::ptr::writefor similar considerations.
Sourceunsafe fn swap<BLOCK: Copy>(&mut self, start: usize, values: &mut BLOCK)
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
BLOCKshould be “plain old data” (seePod). We do not add a trait bound due to Plonky3 types not implementing the trait.- Memory at
startmust be properly aligned forBLOCK. - The data in
valuesshould not overlap with memory inself.
Sourceunsafe fn copy_nonoverlapping<T: Copy>(&mut self, to: usize, data: &[T])
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
Tshould be “plain old data” (seePod). We do not add a trait bound due to Plonky3 types not implementing the trait.- The underlying memory of
datashould not overlap withself. - The starting pointer of
selfshould be aligned toT. - The memory pointer at
toshould be aligned toT.
Sourceunsafe fn get_aligned_slice<T: Copy>(&self, start: usize, len: usize) -> &[T]
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
Tshould be “plain old data” (seePod). We do not add a trait bound due to Plonky3 types not implementing the trait.- Memory at
startmust be properly aligned forT.
Provided Methods§
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.