Skip to main content

LvCell

Struct LvCell 

Source
pub struct LvCell<T>(/* private fields */);
Expand description

Cell<T> for state mutated only from a single logical thread at a time. Marked Sync — the caller is responsible for upholding the single-access invariant (e.g. via a lock like LVGL’s, or by structural guarantees in an embedded setup/run/teardown flow).

Pairs naturally with crate::InitCell for app-wide state.

Implementations§

Source§

impl<T> LvCell<T>

Source

pub const fn new(v: T) -> Self

Construct a new cell holding v. Usable in static/const contexts.

Source

pub fn replace(&self, v: T) -> T

Replace the value, returning the previous one.

Source

pub fn set(&self, v: T)

Store v.

Source

pub fn get_ref(&self) -> &T

Borrow the contents without copying.

§Safety contract

Same single-threaded-access invariant as the rest of LvCell: the caller must ensure no concurrent mutation while the returned reference is live. Useful for hot loops over large Copy payloads (e.g. multi-byte buffers in benchmark inner loops) where get()’s implicit copy would dominate.

Source

pub fn as_ptr(&self) -> *mut T

Raw pointer to the contents — same caveat as core::cell::Cell::as_ptr. Combined with the LvCell single-threaded-access invariant this lets a hot path build a temporary &mut T for in-place updates without going through get()’s Copy + set()’s Copy round-trip.

Source§

impl<T: Copy> LvCell<T>

Source

pub fn get(&self) -> T

Read the current value (copies).

Source

pub fn update(&self, f: impl FnOnce(T) -> T)

Apply f to the current value and store the result.

Trait Implementations§

Source§

impl<T: Send> Sync for LvCell<T>

Auto Trait Implementations§

§

impl<T> !Freeze for LvCell<T>

§

impl<T> !RefUnwindSafe for LvCell<T>

§

impl<T> Send for LvCell<T>
where T: Send,

§

impl<T> Unpin for LvCell<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for LvCell<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for LvCell<T>
where T: UnwindSafe,

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.