pub struct TopicStream<T: Eq + Hash + Clone, M: Clone> { /* private fields */ }Expand description
A topic-based publish-subscribe stream that allows multiple subscribers to listen to messages associated with specific topics.
§Type Parameters
- T: The type representing a topic. Must be hashable, comparable, and clonable.
- M: The message type that will be published and received. Must be clonable.
Implementations§
Source§impl<T: Eq + Hash + Clone, M: Clone> TopicStream<T, M>
impl<T: Eq + Hash + Clone, M: Clone> TopicStream<T, M>
Sourcepub fn subscribe(&self, topics: &[T]) -> MultiTopicReceiver<T, M>
pub fn subscribe(&self, topics: &[T]) -> MultiTopicReceiver<T, M>
Sourcepub async fn publish(&self, topic: &T, message: M) -> Result<(), SendError<M>>
pub async fn publish(&self, topic: &T, message: M) -> Result<(), SendError<M>>
Publishes a message to a specific topic. If the topic has no subscribers, the message is ignored.
§Arguments
- topic: The topic to publish the message to.
- message: The message to send.
§Returns
- Ok(()): If the message was successfully sent or there were no subscribers.
- Err(SendError
): If there was an error sending the message.
Trait Implementations§
Auto Trait Implementations§
impl<T, M> Freeze for TopicStream<T, M>
impl<T, M> !RefUnwindSafe for TopicStream<T, M>
impl<T, M> Send for TopicStream<T, M>
impl<T, M> Sync for TopicStream<T, M>
impl<T, M> Unpin for TopicStream<T, M>
impl<T, M> !UnwindSafe for TopicStream<T, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more