From 681ca1e68560dbd6a89a0243d4a8c80b2f120ee9 Mon Sep 17 00:00:00 2001 From: Brad Clawsie Date: Mon, 30 Nov 2026 12:42:25 -0600 Subject: merge --- learn_22/src/event.rs | 57 --------------------------------------------------- 1 file changed, 57 deletions(-) (limited to 'learn_22/src/event.rs') diff --git a/learn_22/src/event.rs b/learn_22/src/event.rs index 57ca43a..ea80428 100644 --- a/learn_22/src/event.rs +++ b/learn_22/src/event.rs @@ -1,59 +1,3 @@ -<<<<<<< HEAD -use std::collections::BTreeMap; - -type SubscriptionId = u32; - -type Listener = Box; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum Event { - UserCreated { id: u64, name: String }, - UserDeleted { id: u64 }, - MessageReceived { from: u64, text: String }, -} - -pub struct EventBus { - listeners: BTreeMap, - subscription_id: SubscriptionId, -} - -impl EventBus { - pub fn new() -> Self { - Self { - listeners: BTreeMap::new(), - subscription_id: 0, - } - } - - pub fn subscribe(&mut self, callback: F) -> SubscriptionId - where - F: FnMut(&Event) + 'static, - { - let subscription_id = self.subscription_id; - self.listeners.insert(subscription_id, Box::new(callback)); - self.subscription_id += 1; - subscription_id - } - - pub fn unsubscribe(&mut self, id: SubscriptionId) -> bool { - match self.listeners.remove(&id) { - Some(_) => true, - _ => false, - } - } - - pub fn publish(&mut self, event: Event) { - for (_, callback) in &mut self.listeners { - callback(&event); - } - } - - pub fn subscriber_count(&self) -> usize { - self.listeners.len() - } -} -||||||| dfab0ca -======= use std::collections::BTreeMap; use std::ops::AddAssign; @@ -124,4 +68,3 @@ impl EventBus { self.listeners.len() } } ->>>>>>> learn_22 -- cgit v1.2.3