pubsub_bus/
subscriber.rs

1// *************************************************************************
2//
3// Copyright (c) 2025 Andrei Gramakov. All rights reserved.
4//
5// This file is licensed under the terms of the MIT license.
6// For a copy, see: https://opensource.org/licenses/MIT
7//
8// site:    https://agramakov.me
9// e-mail:  mail@agramakov.me
10//
11// *************************************************************************\
12
13use super::BusEvent;
14
15#[cfg(test)]
16mod tests;
17
18/// A trait that defines a subscriber to the event bus.
19/// 
20/// Override `is_subscribed_to` to specify the topics the subscriber is interested in.
21/// The default implementation always returns true.
22/// 
23/// Override `on_event` to handle the event.
24pub trait Subscriber<ContentType, TopicId>: Send + Sync {
25    
26    #[allow(unused_variables)] // This is a default implementation
27    fn is_subscribed_to(&self, topic_id: &TopicId) -> bool {
28        true
29    }
30
31    #[deprecated(since="3.1.0", note="Please use `is_subscribed_to` instead. Using of both methods is not recommended.")]
32    fn get_subscribed_topics(&self) -> Option<Vec<TopicId>> {
33        None
34    }
35
36    fn on_event(&mut self, event: &BusEvent<ContentType, TopicId>);
37}