Trait dioxus::prelude::Readable

source ·
pub trait Readable {
    type Target: 'static + ?Sized;
    type Storage: AnyStorage;

    // Required methods
    fn try_read_unchecked(
        &self
    ) -> Result<<Self::Storage as AnyStorage>::Ref<'static, Self::Target>, BorrowError>;
    fn peek_unchecked(
        &self
    ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>;

    // Provided methods
    fn map<O>(
        self,
        f: impl Fn(&Self::Target) -> &O + 'static
    ) -> MappedSignal<O, Self::Storage>
       where Self: Sized + Clone + 'static { ... }
    fn read(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target> { ... }
    fn try_read(
        &self
    ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError> { ... }
    fn read_unchecked(
        &self
    ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target> { ... }
    fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target> { ... }
    fn cloned(&self) -> Self::Target
       where Self::Target: Clone { ... }
    fn with<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O { ... }
    fn with_peek<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O { ... }
    fn index<I>(
        &self,
        index: I
    ) -> <Self::Storage as AnyStorage>::Ref<'_, <Self::Target as Index<I>>::Output>
       where Self::Target: Index<I> { ... }
}
Available on crate feature signals only.
Expand description

A trait for states that can be read from like crate::Signal, crate::GlobalSignal, or crate::ReadOnlySignal. You may choose to accept this trait as a parameter instead of the concrete type to allow for more flexibility in your API. For example, instead of creating two functions, one that accepts a crate::Signal and one that accepts a crate::GlobalSignal, you can create one function that accepts a Readable type.

Required Associated Types§

source

type Target: 'static + ?Sized

The target type of the reference.

source

type Storage: AnyStorage

The type of the storage this readable uses.

Required Methods§

source

fn try_read_unchecked( &self ) -> Result<<Self::Storage as AnyStorage>::Ref<'static, Self::Target>, BorrowError>

Try to get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal.

NOTE: This method is completely safe because borrow checking is done at runtime.

source

fn peek_unchecked( &self ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>

Get the current value of the signal without checking the lifetime. Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update.

If the signal has been dropped, this will panic.

NOTE: This method is completely safe because borrow checking is done at runtime.

Provided Methods§

source

fn map<O>( self, f: impl Fn(&Self::Target) -> &O + 'static ) -> MappedSignal<O, Self::Storage>
where Self: Sized + Clone + 'static,

Map the readable type to a new type.

source

fn read(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>

Get the current value of the state. If this is a signal, this will subscribe the current scope to the signal. If the value has been dropped, this will panic. Calling this on a Signal is the same as using the signal() syntax to read and subscribe to its value

source

fn try_read( &self ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError>

Try to get the current value of the state. If this is a signal, this will subscribe the current scope to the signal.

source

fn read_unchecked( &self ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>

Get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal.

NOTE: This method is completely safe because borrow checking is done at runtime.

source

fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>

Get the current value of the state without subscribing to updates. If the value has been dropped, this will panic.

source

fn cloned(&self) -> Self::Target
where Self::Target: Clone,

Clone the inner value and return it. If the value has been dropped, this will panic.

source

fn with<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O

Run a function with a reference to the value. If the value has been dropped, this will panic.

source

fn with_peek<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O

Run a function with a reference to the value. If the value has been dropped, this will panic.

source

fn index<I>( &self, index: I ) -> <Self::Storage as AnyStorage>::Ref<'_, <Self::Target as Index<I>>::Output>
where Self::Target: Index<I>,

Index into the inner value and return a reference to the result. If the value has been dropped or the index is invalid, this will panic.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Readable for UseFuture

source§

impl<O, S> Readable for MappedSignal<O, S>
where S: AnyStorage, O: ?Sized,

§

type Target = O

§

type Storage = S

source§

impl<T> Readable for GlobalMemo<T>
where T: PartialEq + 'static,

source§

impl<T> Readable for GlobalSignal<T>
where T: 'static,

source§

impl<T> Readable for Memo<T>
where T: PartialEq,

source§

impl<T> Readable for Resource<T>

source§

impl<T, S> Readable for CopyValue<T, S>
where T: 'static, S: Storage<T>,

§

type Target = T

§

type Storage = S

source§

impl<T, S> Readable for ReadOnlySignal<T, S>
where S: Storage<SignalData<T>>,

§

type Target = T

§

type Storage = S

source§

impl<T, S> Readable for Signal<T, S>
where S: Storage<SignalData<T>>,

§

type Target = T

§

type Storage = S