Struct freya::prelude::UseRef

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>

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>

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)

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>

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

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

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)

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§

§

impl<T> Clone for UseRef<T>

§

fn clone(&self) -> UseRef<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T> PartialEq<UseRef<T>> for UseRef<T>

§

fn eq(&self, other: &UseRef<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<T> To for Twhere T: ?Sized,

§

fn to<T>(self) -> Twhere Self: Into<T>,

Converts to T by calling Into<T>::into.
§

fn try_to<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> CloneAny for Twhere T: Any + Clone,

§

impl<T> Dep for Twhere T: 'static + PartialEq<T> + Clone,