Struct wasm_react::hooks::RefContainer
source · [−]pub struct RefContainer<T> { /* private fields */ }
Expand description
Allows access to the underlying data persisted with use_ref()
.
Panics
The rules of borrowing will be enforced at runtime through a RefCell
,
therefore the methods RefContainer::current()
,
RefContainer::current_mut()
, and RefContainer::set_current()
may
panic accordingly.
Implementations
sourceimpl<T: 'static> RefContainer<T>
impl<T: 'static> RefContainer<T>
sourcepub fn current(&self) -> Ref<'_, T>
pub fn current(&self) -> Ref<'_, T>
Returns a reference to the underlying data.
Panics
Panics if the underlying data is currently mutably borrowed.
sourcepub fn current_mut(&mut self) -> RefMut<'_, T>
pub fn current_mut(&mut self) -> RefMut<'_, T>
Returns a mutable reference to the underlying data.
Panics
Panics if the underlying data is currently borrowed.
sourcepub fn set_current(&mut self, value: T)
pub fn set_current(&mut self, value: T)
Sets the underlying data to the given value.
Panics
Panics if the underlying data is currently borrowed.
sourcepub unsafe fn try_from_js_ref(
js_value: &JsValue
) -> Result<RefContainer<T>, JsValue>
pub unsafe fn try_from_js_ref(
js_value: &JsValue
) -> Result<RefContainer<T>, JsValue>
Converts a JS value into a RefContainer
.
Safety
The following assumptions must hold:
- The JS value has been obtained by creating a
RefContainer
usinguse_ref()
and converting it intoJsValue
. - The React component owning the
RefContainer
hasn’t been unmounted.
Otherwise this might lead to memory issues.
Trait Implementations
sourceimpl<T> AsRef<JsValue> for RefContainer<T>
impl<T> AsRef<JsValue> for RefContainer<T>
sourceimpl<T> Clone for RefContainer<T>
impl<T> Clone for RefContainer<T>
sourceimpl<T: Debug> Debug for RefContainer<T>
impl<T: Debug> Debug for RefContainer<T>
sourceimpl<T> From<RefContainer<T>> for ValueContainer<T>
impl<T> From<RefContainer<T>> for ValueContainer<T>
sourcefn from(value: RefContainer<T>) -> Self
fn from(value: RefContainer<T>) -> Self
Converts to this type from the input type.
sourceimpl<T> From<RefContainer<T>> for JsValue
impl<T> From<RefContainer<T>> for JsValue
sourcefn from(value: RefContainer<T>) -> Self
fn from(value: RefContainer<T>) -> Self
Converts to this type from the input type.
impl<T: 'static> Persisted for RefContainer<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for RefContainer<T>
impl<T> !Send for RefContainer<T>
impl<T> !Sync for RefContainer<T>
impl<T> Unpin for RefContainer<T>
impl<T> !UnwindSafe for RefContainer<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more