pub trait ChannelKind:
Debug
+ Clone
+ Copy
+ Hash
+ Eq
+ Send
+ Sync
+ Serialize
+ DeserializeOwned
+ 'static {
// Required methods
fn priority(&self) -> u8;
fn wire_id(&self) -> u8;
fn from_wire_id(id: u8) -> Option<Self>;
fn from_name(s: &str) -> Option<Self>;
fn name(&self) -> &'static str;
fn is_system(&self) -> bool;
fn all() -> &'static [Self];
}Expand description
Trait for defining multiplexed channel types.
Consumers implement this trait to define their own channel taxonomy. Each channel has a priority, a wire ID for binary encoding, and string representations for JSON/SSE serialization.
§Example
use pushwire_core::ChannelKind;
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
enum MyChannel { Events, Control, System }
impl ChannelKind for MyChannel {
fn priority(&self) -> u8 {
match self {
MyChannel::System | MyChannel::Events => 0,
MyChannel::Control => 1,
}
}
fn wire_id(&self) -> u8 {
match self {
MyChannel::Events => 0x01,
MyChannel::Control => 0x02,
MyChannel::System => 0x05,
}
}
fn from_wire_id(id: u8) -> Option<Self> {
match id {
0x01 => Some(MyChannel::Events),
0x02 => Some(MyChannel::Control),
0x05 => Some(MyChannel::System),
_ => None,
}
}
fn from_name(s: &str) -> Option<Self> {
match s {
"events" => Some(MyChannel::Events),
"control" => Some(MyChannel::Control),
"system" => Some(MyChannel::System),
_ => None,
}
}
fn name(&self) -> &'static str {
match self {
MyChannel::Events => "events",
MyChannel::Control => "control",
MyChannel::System => "system",
}
}
fn is_system(&self) -> bool { matches!(self, MyChannel::System) }
fn all() -> &'static [Self] { &[Self::Events, Self::Control, Self::System] }
}Required Methods§
Sourcefn priority(&self) -> u8
fn priority(&self) -> u8
Priority for outbound queue ordering. Lower values = higher priority. Typical mapping: 0 = high (system, critical UI), 1 = normal, 2 = low (telemetry).
Sourcefn from_wire_id(id: u8) -> Option<Self>
fn from_wire_id(id: u8) -> Option<Self>
Decode from binary wire ID. Returns None for unknown IDs.
Sourcefn from_name(s: &str) -> Option<Self>
fn from_name(s: &str) -> Option<Self>
Parse from canonical string name (for SSE query params, JSON fields).
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.