pub struct Memo<T> { /* private fields */ }Expand description
Handle to a memoized value created by Context::use_memo.
Like State<T>, this is an index handle, not a live borrow — it stores
only the hook slot index and does not keep Context borrowed. That is
the whole point: the handle composes with later ui.* calls, where the old
&T-returning form (now Context::use_memo_ref) held an immutable borrow
of ui that conflicted with any subsequent mutation.
Read the value with get (&T) or copied
(T: Copy).
§Example
let count = ui.use_state(|| 0i32);
let count_val = *count.get(ui);
// Handle releases the `&mut ui` borrow immediately...
let doubled = ui.use_memo(&count_val, |c| c * 2);
// ...so an intervening `ui.*` call composes cleanly.
ui.text("computed:");
ui.text(format!("{}", doubled.copied(ui)));Implementations§
Source§impl<T: 'static> Memo<T>
impl<T: 'static> Memo<T>
Sourcepub fn get<'a>(&self, ui: &'a Context) -> &'a T
pub fn get<'a>(&self, ui: &'a Context) -> &'a T
Read the memoized value.
§Panics
Panics with the slot index and expected type name if the hook at this
index does not hold a MemoSlot<T> — i.e. the rules-of-hooks contract
was broken (hooks called in a different order than the frame that created
the slot). The message matches Context::use_memo’s own mismatch
panic.
§Example
let m = ui.use_memo(&3i32, |d| d * 2);
ui.text(format!("{}", m.get(ui)));Trait Implementations§
impl<T: Eq> Eq for Memo<T>
impl<T> StructuralPartialEq for Memo<T>
Auto Trait Implementations§
impl<T> Freeze for Memo<T>
impl<T> RefUnwindSafe for Memo<T>where
T: RefUnwindSafe,
impl<T> Send for Memo<T>where
T: Send,
impl<T> Sync for Memo<T>where
T: Sync,
impl<T> Unpin for Memo<T>where
T: Unpin,
impl<T> UnsafeUnpin for Memo<T>
impl<T> UnwindSafe for Memo<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.