Channel for sending types that implement a non-dyn compatible trait
⚓ Rust 📅 2025-12-04 👤 surdeus 👁️ 1I am currently implementing the actor pattern for a Zigbee library. I want to use a tokio::sync::mpsc::channel to send command frames to the actor. However the commands are distinct types, but which implement a common trait Command. Alas, Command is not dyn compatible because it has associated constants, such as the command ID and direction.
use crate::cluster::Cluster;
use crate::direction::Direction;
/// Trait to identify a Zigbee command.
pub trait Command: Cluster {
/// The command identifier.
const ID: u8;
/// The command direction.
const DIRECTION: Direction;
}
Is there another way of sending the different types through a channel short of using a humongous enum to account for all possible types?
4 posts - 2 participants
🏷️ Rust_feed