RadioChannel

Trait RadioChannel 

Source
pub trait RadioChannel<T>:
    'static
    + PartialEq
    + Eq
    + Clone
    + Hash {
    // Provided method
    fn derive_channel(self, _radio: &T) -> Vec<Self> { ... }
}
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§

Source

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.

§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 => vec![DataChannel::All],
            DataChannel::Specific(id) => vec![DataChannel::All, DataChannel::Specific(id)],
        }
    }
}

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.

Implementors§