Struct consecuit::hooks::Reference [−][src]
pub struct Reference<T: Default + 'static> { /* fields omitted */ }
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
pub 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.
pub 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.
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.
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.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Reference<T>
impl<T> !UnwindSafe for Reference<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self