From 4aacc15cc3d4f924af34bfb741b138195a3d6dea Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Sun, 10 Nov 2024 17:29:09 +0100 Subject: [PATCH] EventClock: Make Debug representation more compact --- sable_network/src/network/event/clock.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sable_network/src/network/event/clock.rs b/sable_network/src/network/event/clock.rs index d6d2baf5..a02fc4f1 100644 --- a/sable_network/src/network/event/clock.rs +++ b/sable_network/src/network/event/clock.rs @@ -1,8 +1,10 @@ -use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::collections::HashMap; use std::hash::Hash; +use itertools::Itertools; +use serde::{Deserialize, Serialize}; + use crate::prelude::*; /// A vector clock defining, for each server, the most recent event from that @@ -14,7 +16,7 @@ use crate::prelude::*; /// these, a server receiving a remote event can determine whether the incoming /// event can be applied immediately, or whether missing dependencies need to /// be requested. -#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct EventClock(pub HashMap); impl EventClock { @@ -112,3 +114,16 @@ impl PartialOrd for EventClock { } } } + +impl std::fmt::Debug for EventClock { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut entries: Vec<_> = self.0.iter().collect(); + entries.sort_unstable(); + let entries = entries + .into_iter() + .map(|(k, v)| format!("{} => {}", **k, v.as_u64())) + .join(", "); + write!(f, "EventClock({})", entries)?; + Ok(()) + } +}