Trait freya::prelude::Readable

pub trait Readable<T = ()>where
    T: 'static,{
    type Ref<R: 'static + ?Sized>: Deref<Target = R>;

    // Required methods
    fn map_ref<I, U, F>(ref_: Self::Ref<I>, f: F) -> Self::Ref<U>
       where F: FnOnce(&I) -> &U,
             U: ?Sized;
    fn try_map_ref<I, U, F>(ref_: Self::Ref<I>, f: F) -> Option<Self::Ref<U>>
       where F: FnOnce(&I) -> Option<&U>,
             U: ?Sized;
    fn read(&self) -> Self::Ref<T>;
    fn peek(&self) -> Self::Ref<T>;

    // Provided methods
    fn cloned(&self) -> T
       where T: Clone { ... }
    fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O { ... }
    fn with_peek<O>(&self, f: impl FnOnce(&T) -> O) -> O { ... }
    fn index<I>(&self, index: I) -> Self::Ref<<T as Index<I>>::Output>
       where T: Index<I> { ... }
}
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§

type Ref<R: 'static + ?Sized>: Deref<Target = R>

The type of the reference.

Required Methods§

fn map_ref<I, U, F>(ref_: Self::Ref<I>, f: F) -> Self::Ref<U>where F: FnOnce(&I) -> &U, U: ?Sized,

Map the reference to a new type.

fn try_map_ref<I, U, F>(ref_: Self::Ref<I>, f: F) -> Option<Self::Ref<U>>where F: FnOnce(&I) -> Option<&U>, U: ?Sized,

Try to map the reference to a new type.

fn read(&self) -> Self::Ref<T>

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.

fn peek(&self) -> Self::Ref<T>

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

Provided Methods§

fn cloned(&self) -> Twhere T: Clone,

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

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

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

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

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

fn index<I>(&self, index: I) -> Self::Ref<<T as Index<I>>::Output>where T: 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§

§

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

§

type Ref<R: 'static + ?Sized> = GenerationalRef<Ref<'static, R>>

§

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

§

type Ref<R: 'static + ?Sized> = GenerationalRef<Ref<'static, R>>

§

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

§

type Ref<R: 'static + ?Sized> = <S as AnyStorage>::Ref<R>

§

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

§

type Ref<R: 'static + ?Sized> = <S as AnyStorage>::Ref<R>

§

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

§

type Ref<R: 'static + ?Sized> = <S as AnyStorage>::Ref<R>