pub trait Readable {
type Target: 'static + ?Sized;
type Storage: AnyStorage;
// Required methods
fn try_read(
&self
) -> Result<<Self::Storage as AnyStorage>::Ref<Self::Target>, BorrowError>;
fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<Self::Target>;
// Provided methods
fn map<O>(
self,
f: impl Fn(&Self::Target) -> &O + 'static
) -> MappedSignal<O, Self::Storage>
where Self: Clone + Sized + 'static { ... }
fn read(&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> { ... }
}
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 Storage: AnyStorage
type Storage: AnyStorage
The type of the storage this readable uses.
Required Methods§
fn try_read(
&self
) -> Result<<Self::Storage as AnyStorage>::Ref<Self::Target>, BorrowError>
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. If the value has been dropped, this will panic.
fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<Self::Target>
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.
Provided Methods§
fn map<O>(
self,
f: impl Fn(&Self::Target) -> &O + 'static
) -> MappedSignal<O, Self::Storage>
fn map<O>( self, f: impl Fn(&Self::Target) -> &O + 'static ) -> MappedSignal<O, Self::Storage>
Map the readable type to a new type.
fn read(&self) -> <Self::Storage as AnyStorage>::Ref<Self::Target>
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.
fn cloned(&self) -> Self::Target
fn cloned(&self) -> Self::Target
Clone the inner value and return it. If the value has been dropped, this will panic.
fn with<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O
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.