pub trait PubsubTopic:
Clone
+ Hash
+ Eq { }Expand description
A trait that defines the requirements for types that can be used as Pubsub topics.
Any type that implements Clone, Hash, and Eq can be used as a topic in the Pubsub system. This includes common types like String, &str, and custom types that implement these traits.
The trait is automatically implemented for all types that satisfy the trait bounds, so users don’t need to explicitly implement it for their types.
§Requirements
- Clone: Topics need to be cloned when creating subscriptions and publishing messages
- Hash: Topics are used as keys in a hash map for efficient lookups
- Eq: Topics need to be comparable for equality when matching subscriptions
§Examples
// String implements PubsubTopic
let topic: String = "my_topic".to_owned();
// &str implements PubsubTopic
let topic: &str = "my_topic";
// Custom types can be used if they implement the required traits
#[derive(Clone, Hash, Eq, PartialEq)]
struct CustomTopic {
id: u32,
name: String,
}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.