Struct Radio
pub struct Radio<Value, Channel>where
Channel: RadioChannel<Value>,
Value: 'static,{ /* private fields */ }Available on crate feature
radio only.Expand description
Radio lets you access the state and is subscribed given it’s Channel.
Implementations§
§impl<Value, Channel> Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> Radio<Value, Channel>where
Channel: RadioChannel<Value>,
pub fn read(&self) -> <UnsyncStorage as AnyStorage>::Ref<'_, Value>
pub fn read(&self) -> <UnsyncStorage as AnyStorage>::Ref<'_, Value>
pub fn with(
&self,
cb: impl FnOnce(<UnsyncStorage as AnyStorage>::Ref<'_, Value>),
)
pub fn with( &self, cb: impl FnOnce(<UnsyncStorage as AnyStorage>::Ref<'_, Value>), )
Read the current state value inside a callback.
Example:
ⓘ
radio.with(|value| {
// Do something with `value`
});pub fn write(&mut self) -> RadioGuard<Value, Channel>
pub fn write(&mut self) -> RadioGuard<Value, Channel>
pub 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`
});pub fn write_channel(&mut self, channel: Channel) -> RadioGuard<Value, Channel>
pub fn write_channel(&mut self, channel: Channel) -> RadioGuard<Value, Channel>
pub 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`
});pub 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
}
});pub 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§
§impl<Value, Channel> Clone for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> Clone for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
§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>,
fn read(&mut self) -> <UnsyncStorage as AnyStorage>::Ref<'static, Value>
fn peek(&mut self) -> <UnsyncStorage as AnyStorage>::Ref<'static, Value>
fn write(&mut self) -> <UnsyncStorage as AnyStorage>::Mut<'static, Value>
fn write_if( &mut self, with: impl FnOnce(<UnsyncStorage as AnyStorage>::Mut<'static, Value>) -> bool, )
§impl<Value, Channel> PartialEq for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
impl<Value, Channel> PartialEq for Radio<Value, Channel>where
Channel: RadioChannel<Value>,
§impl<Data, Channel, Action> RadioAsyncReducer for Radio<Data, Channel>where
Data: DataAsyncReducer<Channel = Channel, Action = Action>,
Channel: RadioChannel<Data>,
impl<Data, Channel, Action> RadioAsyncReducer for Radio<Data, Channel>where
Data: DataAsyncReducer<Channel = Channel, Action = Action>,
Channel: RadioChannel<Data>,
type Action = Action
fn async_apply( &mut self, action: <Radio<Data, Channel> as RadioAsyncReducer>::Action, )
§impl<Data, Channel, Action> RadioReducer for Radio<Data, Channel>where
Data: DataReducer<Channel = Channel, Action = Action>,
Channel: RadioChannel<Data>,
impl<Data, Channel, Action> RadioReducer for Radio<Data, Channel>where
Data: DataReducer<Channel = Channel, Action = Action>,
Channel: RadioChannel<Data>,
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