Struct PersistentBuff

Source
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

Source

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.

Source

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.

Source

pub fn take_raw() -> Option<&'static mut [u8]>

Get the raw persistent slice.

Source

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.

Source

pub fn valid(&self) -> bool

Verify if the persistent buffer has valid data in it.

Source

pub fn take(self) -> Option<&'static mut [u8]>

Take the static internal buffer from the managed buff if valid

Source

pub fn take_reset<F>(self, f: F) -> &'static mut [u8]
where F: FnOnce(&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

Source

pub fn take_validate<F>(self, f: F) -> &'static 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. Then the static buff is taken from the managed buff

Source

pub fn get(&mut self) -> Option<&mut [u8]>

Get the buffer if the data is valid, if not, return None

Source

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

Source

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. This is to make sure the data in it is always “valid” and not garbage after a powerloss.

Source

pub fn invalidate(&mut self)

Mark the buffer as invalid

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.