diff --git a/chombot-common/src/data_watcher.rs b/chombot-common/src/data_watcher.rs index ed83457..a2570a3 100644 --- a/chombot-common/src/data_watcher.rs +++ b/chombot-common/src/data_watcher.rs @@ -9,19 +9,22 @@ use tokio::time::sleep; const DATA_UPDATE_INTERVAL: Duration = Duration::from_secs(60 * 10); -pub trait WatchableData { +pub trait WatchableData: Sized { type Diff; #[must_use] - fn should_notify<'a>(&'a self, new: &'a Self) -> Option; - fn update(&mut self, new: Self); + fn should_notify(&self, new: &Self) -> Option; + + fn update(&mut self, new: Self) { + *self = new; + } } impl WatchableData for Option { type Diff = T::Diff; #[must_use] - fn should_notify<'a>(&'a self, new: &'a Self) -> Option { + fn should_notify(&self, new: &Self) -> Option { match (&self, &new) { (Some(o), Some(n)) => o.should_notify(n), _ => None, diff --git a/chombot-common/src/tournaments_watcher/ema.rs b/chombot-common/src/tournaments_watcher/ema.rs index ac9b052..1851501 100644 --- a/chombot-common/src/tournaments_watcher/ema.rs +++ b/chombot-common/src/tournaments_watcher/ema.rs @@ -46,17 +46,13 @@ impl Tournaments { impl WatchableData for Tournaments { type Diff = TournamentStatuses; - fn should_notify<'a>(&'a self, new: &'a Self) -> Option { + fn should_notify(&self, new: &Self) -> Option { if self == new { None } else { Some(tournaments_diff(self, new)) } } - - fn update(&mut self, new: Self) { - *self = new; - } } #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/chombot-kcc/src/ranking_watcher/usma.rs b/chombot-kcc/src/ranking_watcher/usma.rs index 456d92b..a28aa80 100644 --- a/chombot-kcc/src/ranking_watcher/usma.rs +++ b/chombot-kcc/src/ranking_watcher/usma.rs @@ -48,7 +48,7 @@ impl Ranking { impl WatchableData for Ranking { type Diff = Vec; - fn should_notify<'a>(&'a self, new: &'a Self) -> Option> { + fn should_notify(&self, new: &Self) -> Option> { let new_changed = new.get_changed(); if new_changed.is_empty() || new_changed == self.get_changed() { None @@ -56,10 +56,6 @@ impl WatchableData for Ranking { Some(new_changed.into_iter().cloned().collect()) } } - - fn update(&mut self, new: Self) { - *self = new; - } } fn first_element_child<'a>(e: &'a ElementRef) -> Option<&'a Element> {