Trait RadioChannel
pub trait RadioChannel<T>:
'static
+ PartialEq
+ Eq
+ Clone
+ Hash {
// Provided method
fn derive_channel(self, _radio: &T) -> Vec<Self> { ... }
}radio and non-crate feature tracing only.Expand description
Defines a channel for radio communication.
Channels are used to subscribe to specific changes in the global state.
Each channel must implement this trait to be used with RadioStation and Radio.
Channels allow fine-grained control over which components re-render when the state changes. Components only re-render when a channel they are subscribed to is notified.
§Example
#[derive(PartialEq, Eq, Clone, Debug, Copy, Hash)]
pub enum DataChannel {
ListCreation,
SpecificListItemUpdate(usize),
}
impl RadioChannel<Data> for DataChannel {}Provided Methods§
fn derive_channel(self, _radio: &T) -> Vec<Self>
fn derive_channel(self, _radio: &T) -> Vec<Self>
Derive additional channels based on the current state value. This allows a single write operation to notify multiple channels.
By default, returns a vector containing only self.
Declaring related channels here is a best practice enforced by design. Making every write list them by hand is verbose and easy to get wrong. Doing it once here keeps every write consistent.
§Example
#[derive(PartialEq, Eq, Clone, Debug, Copy, Hash)]
pub enum DataChannel {
All,
Specific(usize),
}
impl RadioChannel<Data> for DataChannel {
fn derive_channel(self, data: &Data) -> Vec<Self> {
match self {
DataChannel::All => {
let mut channels = vec![DataChannel::All];
channels.extend((0..data.items.len()).map(DataChannel::Specific));
channels
}
DataChannel::Specific(_) => vec![self],
}
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.