pub struct UseRef<T> { /* private fields */ }
Expand description
A type created by the use_ref
hook. See its documentation for more details.
Implementations§
§impl<T> UseRef<T>
impl<T> UseRef<T>
pub fn read(&self) -> Ref<'_, T>
pub fn read(&self) -> Ref<'_, T>
Read the value in the RefCell into a Ref
. If this method is called
while other values are still being read
or write
, then your app will crash.
Be very careful when working with this method. If you can, consider using
the with
and with_mut
methods instead, choosing to render Elements
during the read calls.
pub fn write(&self) -> RefMut<'_, T>
pub fn write(&self) -> RefMut<'_, T>
Mutably unlock the value in the RefCell. This will mark the component as “dirty”
Uses to write
should be as short as possible.
Be very careful when working with this method. If you can, consider using
the with
and with_mut
methods instead, choosing to render Elements
during the read and write calls.
pub fn set(&self, new: T)
pub fn set(&self, new: T)
Set the curernt value to new_value
. This will mark the component as “dirty”
This change will propagate immediately, so any other contexts that are
using this RefCell will also be affected. If called during an async context,
the component will not be re-rendered until the next .await
call.
pub fn write_silent(&self) -> RefMut<'_, T>
pub fn write_silent(&self) -> RefMut<'_, T>
Mutably unlock the value in the RefCell. This will not mark the component as dirty. This is useful if you want to do some work without causing the component to re-render.
Uses to write
should be as short as possible.
Be very careful when working with this method. If you can, consider using
the with
and with_mut
methods instead, choosing to render Elements
pub fn with<O>(&self, immutable_callback: impl FnOnce(&T) -> O) -> O
pub fn with<O>(&self, immutable_callback: impl FnOnce(&T) -> O) -> O
Take a reference to the inner value termporarily and produce a new value
Note: You can always “reborrow” the value through the RefCell. This method just does it for you automatically.
let val = use_ref(|| HashMap::<u32, String>::new());
// use reborrowing
let inner = &*val.read();
// or, be safer and use `with`
val.with(|i| println!("{:?}", i));
pub fn with_mut<O>(&self, mutable_callback: impl FnOnce(&mut T) -> O) -> O
pub fn with_mut<O>(&self, mutable_callback: impl FnOnce(&mut T) -> O) -> O
Take a reference to the inner value termporarily and produce a new value, modifying the original in place.
Note: You can always “reborrow” the value through the RefCell. This method just does it for you automatically.
let val = use_ref(|| HashMap::<u32, String>::new());
// use reborrowing
let inner = &mut *val.write();
// or, be safer and use `with`
val.with_mut(|i| i.insert(1, "hi"));
pub fn needs_update(&self)
pub fn needs_update(&self)
Call the inner callback to mark the originator component as dirty.
This will cause the component to be re-rendered after the current scope has ended or the current async task has been yielded through await.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for UseRef<T>
impl<T> !Send for UseRef<T>
impl<T> !Sync for UseRef<T>
impl<T> Unpin for UseRef<T>
impl<T> !UnwindSafe for UseRef<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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.