pub struct Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Value: 'static,{ /* private fields */ }Expand description
Radio lets you access the state and is subscribed given it’s Channel.
Implementations§
Source§impl<Value, Channel> Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Sourcepub fn read(&self) -> ReadRef<'_, Value>
pub fn read(&self) -> ReadRef<'_, Value>
Read the current state value.
Example:
let value = radio.read();Sourcepub fn with(&self, cb: impl FnOnce(ReadRef<'_, Value>))
pub fn with(&self, cb: impl FnOnce(ReadRef<'_, Value>))
Read the current state value inside a callback.
Example:
radio.with(|value| {
// Do something with `value`
});Sourcepub fn write(&mut self) -> RadioGuard<Value, Channel>
pub fn write(&mut self) -> RadioGuard<Value, Channel>
Modify the state using the channel this radio was created with.
Example:
radio.write().value = 1;Sourcepub fn write_with(&mut self, cb: impl FnOnce(RadioGuard<Value, Channel>))
pub fn write_with(&mut self, cb: impl FnOnce(RadioGuard<Value, Channel>))
Get a mutable reference to the current state value, inside a callback.
Example:
radio.write_with(|value| {
// Modify `value`
});Sourcepub fn write_channel(&mut self, channel: Channel) -> RadioGuard<Value, Channel>
pub fn write_channel(&mut self, channel: Channel) -> RadioGuard<Value, Channel>
Sourcepub fn write_channel_with(
&mut self,
channel: Channel,
cb: impl FnOnce(RadioGuard<Value, Channel>),
)
pub fn write_channel_with( &mut self, channel: Channel, cb: impl FnOnce(RadioGuard<Value, Channel>), )
Get a mutable reference to the current state value, inside a callback.
Example:
radio.write_channel_with(Channel::Whatever, |value| {
// Modify `value`
});Sourcepub fn write_with_channel_selection(
&mut self,
cb: impl FnOnce(&mut Value) -> ChannelSelection<Channel>,
) -> ChannelSelection<Channel>
pub fn write_with_channel_selection( &mut self, cb: impl FnOnce(&mut Value) -> ChannelSelection<Channel>, ) -> ChannelSelection<Channel>
Get a mutable reference to the current state value, inside a callback that returns the channel to be used.
Example:
radio.write_with_channel_selection(|value| {
// Modify `value`
if value.cool {
ChannelSelection::Select(Channel::Whatever)
} else {
ChannelSelection::Silence
}
});Sourcepub fn write_silently(&mut self) -> RadioGuard<Value, Channel>
pub fn write_silently(&mut self) -> RadioGuard<Value, Channel>
Modify the state silently, no component will be notified.
This is not recommended, the only intended usage for this is inside RadioAsyncReducer.
Trait Implementations§
Source§impl<Value, Channel> Clone for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> Clone for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Source§impl<Value, Channel> MutView<'static, Value> for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> MutView<'static, Value> for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Source§impl<Value, Channel> PartialEq for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> PartialEq for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Source§impl<Data: DataAsyncReducer<Channel = Channel, Action = Action>, Channel: RadioChannel<Data>, Action> RadioAsyncReducer for Radio<Data, Channel>
impl<Data: DataAsyncReducer<Channel = Channel, Action = Action>, Channel: RadioChannel<Data>, Action> RadioAsyncReducer for Radio<Data, Channel>
Source§impl<Data: DataReducer<Channel = Channel, Action = Action>, Channel: RadioChannel<Data>, Action> RadioReducer for Radio<Data, Channel>
impl<Data: DataReducer<Channel = Channel, Action = Action>, Channel: RadioChannel<Data>, Action> RadioReducer for Radio<Data, Channel>
impl<Value, Channel> Copy for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Auto Trait Implementations§
impl<Value, Channel> Freeze for Radio<Value, Channel>
impl<Value, Channel> !RefUnwindSafe for Radio<Value, Channel>
impl<Value, Channel> !Send for Radio<Value, Channel>
impl<Value, Channel> !Sync for Radio<Value, Channel>
impl<Value, Channel> Unpin for Radio<Value, Channel>
impl<Value, Channel> !UnwindSafe for Radio<Value, Channel>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ComponentProps for T
impl<T> ComponentProps for T
fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more