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/// Override get_subscribed_topics to return a list of topics the subscriber is interested in.
20/// If the subscriber is interested in all topics, thre si a default implementation that returns None.
21/// Override on_event to handle the event.
22pub trait Subscriber<ContentType, TopicId>: Send + Sync {
23    fn get_subscribed_topics(&self) -> Option<Vec<TopicId>> {
24        None
25    }
26
27    fn on_event(&mut self, event: &BusEvent<ContentType, TopicId>);
28}