Trait freya::prelude::Writable

pub trait Writable: Readable {
    type Mut<R: 'static + ?Sized>: DerefMut<Target = R> + 'static;

    // Required methods
    fn map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Self::Mut<U>
       where F: FnOnce(&mut I) -> &mut U,
             I: ?Sized,
             U: ?Sized;
    fn try_map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Option<Self::Mut<U>>
       where F: FnOnce(&mut I) -> Option<&mut U>,
             I: ?Sized,
             U: ?Sized;
    fn try_write(&self) -> Result<Self::Mut<Self::Target>, BorrowMutError>;

    // Provided methods
    fn write(&mut self) -> Self::Mut<Self::Target> { ... }
    fn with_mut<O>(&mut self, f: impl FnOnce(&mut Self::Target) -> O) -> O { ... }
    fn set(&mut self, value: Self::Target)
       where Self::Target: Sized { ... }
    fn toggle(&mut self)
       where Self::Target: Not<Output = Self::Target> + Clone { ... }
    fn index_mut<I>(
        &mut self,
        index: I
    ) -> Self::Mut<<Self::Target as Index<I>>::Output>
       where Self::Target: IndexMut<I> { ... }
    fn take(&mut self) -> Self::Target
       where Self::Target: Default { ... }
    fn replace(&mut self, value: Self::Target) -> Self::Target
       where Self::Target: Sized { ... }
}
Expand description

A trait for states that can be read from like crate::Signal, or crate::GlobalSignal. 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 Writable type.

Required Associated Types§

type Mut<R: 'static + ?Sized>: DerefMut<Target = R> + 'static

The type of the reference.

Required Methods§

fn map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Self::Mut<U>
where F: FnOnce(&mut I) -> &mut U, I: ?Sized, U: ?Sized,

Map the reference to a new type.

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

Try to map the reference to a new type.

fn try_write(&self) -> Result<Self::Mut<Self::Target>, BorrowMutError>

Try to get a mutable reference to the value. If the value has been dropped, this will panic.

Provided Methods§

fn write(&mut self) -> Self::Mut<Self::Target>

Get a mutable reference to the value. If the value has been dropped, this will panic.

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

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

fn set(&mut self, value: Self::Target)
where Self::Target: Sized,

Set the value of the signal. This will trigger an update on all subscribers.

fn toggle(&mut self)
where Self::Target: Not<Output = Self::Target> + Clone,

Invert the boolean value of the signal. This will trigger an update on all subscribers.

fn index_mut<I>( &mut self, index: I ) -> Self::Mut<<Self::Target as Index<I>>::Output>
where Self::Target: IndexMut<I>,

Index into the inner value and return a reference to the result.

fn take(&mut self) -> Self::Target
where Self::Target: Default,

Takes the value out of the Signal, leaving a Default in its place.

fn replace(&mut self, value: Self::Target) -> Self::Target
where Self::Target: Sized,

Replace the value in the Signal, returning the old value.

Object Safety§

This trait is not object safe.

Implementors§

§

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

§

type Mut<R: 'static + ?Sized> = Write<R>

§

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

§

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

§

impl<T, S> Writable for Signal<T, S>
where T: 'static, S: Storage<SignalData<T>>,

§

type Mut<R: 'static + ?Sized> = Write<R, S>