pub struct StateReader<const STATE_MAX: usize> { /* private fields */ }Expand description
Reader handle for a state layout.
Readers use the parity protocol to avoid torn reads: they only return a snapshot if seq
was even and unchanged across the read.
Implementations§
Source§impl<const STATE_MAX: usize> StateReader<STATE_MAX>
impl<const STATE_MAX: usize> StateReader<STATE_MAX>
Sourcepub fn new(inner: &StateLayoutCell<STATE_MAX>) -> Self
pub fn new(inner: &StateLayoutCell<STATE_MAX>) -> Self
Create a reader over a mapped layout without validating it.
Prefer try_new when constructing from an untrusted mapping.
Sourcepub fn try_new(inner: &StateLayoutCell<STATE_MAX>) -> Result<Self, Error>
pub fn try_new(inner: &StateLayoutCell<STATE_MAX>) -> Result<Self, Error>
Create a reader after validating the mapped layout.
Sourcepub fn try_load_into(
&self,
out: &mut [u8],
) -> Result<Option<(usize, u64)>, usize>
pub fn try_load_into( &self, out: &mut [u8], ) -> Result<Option<(usize, u64)>, usize>
Load the latest stable state snapshot into out.
Returns Ok(None) when:
- there is no published state yet (
len == 0) - a writer is in progress (odd
seq) - a write raced with the read (sequence changed)
§Errors
Returns Err(required_len) when out is too small to hold the current snapshot.
Trait Implementations§
impl<const STATE_MAX: usize> Send for StateReader<STATE_MAX>
impl<const STATE_MAX: usize> Sync for StateReader<STATE_MAX>
Auto Trait Implementations§
impl<const STATE_MAX: usize> Freeze for StateReader<STATE_MAX>
impl<const STATE_MAX: usize> !RefUnwindSafe for StateReader<STATE_MAX>
impl<const STATE_MAX: usize> Unpin for StateReader<STATE_MAX>
impl<const STATE_MAX: usize> !UnwindSafe for StateReader<STATE_MAX>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more