pub struct Reference<T: Default + 'static> { /* private fields */ }Expand description
A reference with interior mutability. Somewhat like RefCell. Returned by use_ref.
This can be read from and written to anytime. Writing to it does not trigger rerender.
This is often not neccessary. Use super::use_state() instead.
Implementations§
Source§impl<T: Default + 'static> Reference<T>
impl<T: Default + 'static> Reference<T>
Sourcepub fn visit_with<Ret: 'static, F: FnOnce(&T) -> Ret>(
&self,
func: F,
) -> Result<Ret, SubtreeUnmountedError>
pub fn visit_with<Ret: 'static, F: FnOnce(&T) -> Ret>( &self, func: F, ) -> Result<Ret, SubtreeUnmountedError>
Run the given closure with a borrow of the data inside the Reference as argument.
Returns a Result with the Ok variant being the return value of your closure.
The error variant is SubtreeUnmountedError.
This error is thrown if this function is called when the subtree where the use_ref this comes from had been unmounted.
Sourcepub fn visit_mut_with<Ret: 'static, F: FnOnce(&mut T) -> Ret>(
&self,
func: F,
) -> Result<Ret, SubtreeUnmountedError>
pub fn visit_mut_with<Ret: 'static, F: FnOnce(&mut T) -> Ret>( &self, func: F, ) -> Result<Ret, SubtreeUnmountedError>
Run the given closure with a mutable borrow of the data inside the Reference as argument.
Returns a Result with the Ok variant being the return value of your closure.
The error variant is SubtreeUnmountedError.
This error is thrown if this function is called when the subtree where the use_ref this comes from had been unmounted.
Sourcepub fn set_in(&self, value: T) -> Result<(), SubtreeUnmountedError>
pub fn set_in(&self, value: T) -> Result<(), SubtreeUnmountedError>
Set the value in the Ref to the given value.
This does not trigger a rerender.
The error variant is SubtreeUnmountedError.
This error is thrown if this function is called when the subtree where the use_ref this comes from had been unmounted.
Source§impl<T: Clone + Default + 'static> Reference<T>
impl<T: Clone + Default + 'static> Reference<T>
Sourcepub fn clone_out(&self) -> Result<T, SubtreeUnmountedError>
pub fn clone_out(&self) -> Result<T, SubtreeUnmountedError>
Return a clone of the value inside the Ref.
The Ok variant is said value.
The error variant is SubtreeUnmountedError.
This error is thrown if this function is called when the subtree where the use_ref this comes from had been unmounted.