pub struct RefHandle<T> { /* private fields */ }Expand description
A handle to a mutable reference that persists across renders
This mirrors React’s useRef return value. Unlike StateHandle,
mutations do NOT trigger re-renders.
Implementations§
Source§impl<T> RefHandle<T>
impl<T> RefHandle<T>
Sourcepub fn new<F>(initializer: F) -> Selfwhere
F: FnOnce() -> T,
pub fn new<F>(initializer: F) -> Selfwhere
F: FnOnce() -> T,
Create a new ref handle with an initial value
Sourcepub fn from_container(container: Arc<RefContainer<T>>) -> Self
pub fn from_container(container: Arc<RefContainer<T>>) -> Self
Create a ref handle from an existing container
Sourcepub fn update<F>(&self, updater: F)
pub fn update<F>(&self, updater: F)
Update the value using a mutable closure (does NOT trigger re-render)
Sourcepub fn with_mut<F, R>(&self, mutator: F) -> R
pub fn with_mut<F, R>(&self, mutator: F) -> R
Access the value mutably with a closure (does NOT trigger re-render)
Sourcepub fn take(&self) -> Twhere
T: Default,
pub fn take(&self) -> Twhere
T: Default,
Take the value, leaving Default::default() in its place
Sourcepub fn container(&self) -> &Arc<RefContainer<T>> ⓘ
pub fn container(&self) -> &Arc<RefContainer<T>> ⓘ
Get access to the underlying container (for advanced use cases)
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for RefHandle<T>
impl<T> !UnwindSafe for RefHandle<T>
impl<T> Freeze for RefHandle<T>
impl<T> Send for RefHandle<T>
impl<T> Sync for RefHandle<T>
impl<T> Unpin for RefHandle<T>
impl<T> UnsafeUnpin for RefHandle<T>
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more