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§
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 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,
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.
Provided Methods§
fn cloned(&self) -> Twhere
T: Clone,
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
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.
Object Safety§
This trait is not object safe.