pub trait Writable<T>: Readable<T>where
T: 'static,{
type Mut<R: 'static + ?Sized>: DerefMut<Target = R>;
// Required methods
fn map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Self::Mut<U>
where F: FnOnce(&mut I) -> &mut U,
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>,
U: ?Sized;
fn try_write(&self) -> Result<Self::Mut<T>, BorrowMutError>;
// Provided methods
fn write(&self) -> Self::Mut<T> { ... }
fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O { ... }
fn set(&mut self, value: T) { ... }
fn toggle(&mut self)
where T: Not<Output = T> + Clone { ... }
fn index_mut<I>(&self, index: I) -> Self::Mut<<T as Index<I>>::Output>
where T: IndexMut<I> { ... }
fn take(&self) -> T
where T: Default { ... }
fn replace(&self, value: T) -> T { ... }
}
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§
Required Methods§
fn map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Self::Mut<U>where
F: FnOnce(&mut I) -> &mut U,
U: ?Sized,
fn map_mut<I, U, F>(ref_: Self::Mut<I>, f: F) -> Self::Mut<U>where F: FnOnce(&mut I) -> &mut U, U: ?Sized,
Map the reference to a new type.
Provided Methods§
fn write(&self) -> Self::Mut<T>
fn write(&self) -> Self::Mut<T>
Get a mutable reference to the value. If the value has been dropped, this will panic.
fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O
fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> 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: T)
fn set(&mut self, value: T)
Set the value of the signal. This will trigger an update on all subscribers.
fn toggle(&mut self)where
T: Not<Output = T> + Clone,
fn toggle(&mut self)where T: Not<Output = T> + Clone,
Invert the boolean value of the signal. This will trigger an update on all subscribers.
fn index_mut<I>(&self, index: I) -> Self::Mut<<T as Index<I>>::Output>where
T: IndexMut<I>,
fn index_mut<I>(&self, index: I) -> Self::Mut<<T as Index<I>>::Output>where T: IndexMut<I>,
Index into the inner value and return a reference to the result.
fn take(&self) -> Twhere
T: Default,
fn take(&self) -> Twhere T: Default,
Takes the value out of the Signal, leaving a Default in its place.
fn replace(&self, value: T) -> T
fn replace(&self, value: T) -> T
Replace the value in the Signal, returning the old value.