pub struct PersistentBuff { /* private fields */ }
Expand description
Strut to request the persistent buff and manage it somewhat “safely”. When acquiring the buffer you need to validate/init it to a known sate.
Implementations§
Source§impl PersistentBuff
impl PersistentBuff
Sourcepub fn take_managed() -> Option<Self>
pub fn take_managed() -> Option<Self>
Take a managed version fo the persistent buff. Allows to check if the buffer is valid or not before usage. Note that compared to 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 take(self) -> Option<&'static mut [u8]>
pub fn take(self) -> Option<&'static mut [u8]>
Take the static internal buffer from the managed buff if valid
Sourcepub fn take_reset<F>(self, f: F) -> &'static mut [u8]
pub fn take_reset<F>(self, f: F) -> &'static mut [u8]
Force to reset the buffer to a known state via the closure and mark as valid for next boot then takes the static buff from the managed buff
Sourcepub fn take_validate<F>(self, f: F) -> &'static mut [u8]
pub fn take_validate<F>(self, f: F) -> &'static 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. Then the static buff is taken from the managed buff
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]
pub fn reset<F>(&mut self, f: F) -> &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]
pub fn validate<F>(&mut self, f: F) -> &mut [u8]
Check if the buffer is valid, if not call the provided closure. Then mark the buffer as valid. 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