Struct persistent_buff::PersistentBuff
source · [−]pub struct PersistentBuff { /* private fields */ }
Expand description
Strut to request the persistent buff and manage it safely
.
When acquiring the buffer you need to validate/init it to a known sate.
Implementations
sourceimpl PersistentBuff
impl PersistentBuff
sourcepub fn take_managed() -> Option<Self>
pub fn take_managed() -> Option<Self>
Take a managed version fo the persistent buff. Allow to check if the buffer is valid or not before usage. Note that vs the Self::take function, you will lose some bytes for storage of the marker.
sourcepub unsafe fn steal_managed() -> Self
pub unsafe fn steal_managed() -> Self
Steal a managed version for the persistent buff without check. See Self::take_managed
Safety
Calling this function could allow to have two mutable reference to the same buffer. Make sure to only have one reference at a time to avoid multiple mutable reference.
sourcepub unsafe fn steal() -> &'static mut [u8]
pub unsafe fn steal() -> &'static mut [u8]
Steal the raw persistent slice. Ignore if it was already taken or not.
Safety
Calling this function could allow to have two mutable reference to the same buffer. Make sure to only have one reference at a time to avoid multiple mutable reference.
sourcepub fn get(&mut self) -> Option<&mut [u8]>
pub fn get(&mut self) -> Option<&mut [u8]>
Get the buffer if the data is valid, if not, return None
sourcepub fn reset<F>(&mut self, f: F) -> &mut [u8]where
F: FnOnce(&mut [u8]),
pub fn reset<F>(&mut self, f: F) -> &mut [u8]where
F: FnOnce(&mut [u8]),
Force reset the buffer to a known state via the closure, mark as valid and return the buffer
sourcepub fn validate<F>(&mut self, f: F) -> &mut [u8]where
F: FnOnce(&mut [u8]),
pub fn validate<F>(&mut self, f: F) -> &mut [u8]where
F: FnOnce(&mut [u8]),
Check if the buffer is valid, if not call the provided closure. Then mark the buffer as valid and initialize it to a known state. This is to make sure the data in it is always “valid” and not garbage after a powerloss.
sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Mark the buffer as invalid