mz_timely_util/
antichain.rs1use std::fmt::{Display, Error, Formatter};
17
18use timely::progress::frontier::{Antichain, AntichainRef, MutableAntichain};
19
20pub trait AntichainExt {
21 type Pretty<'a>: Display
22 where
23 Self: 'a;
24
25 fn pretty(&self) -> Self::Pretty<'_>;
26}
27
28impl<T: Display + 'static> AntichainExt for Antichain<T> {
29 type Pretty<'a> = FrontierPrinter<AntichainRef<'a, T>>;
30
31 fn pretty(&self) -> Self::Pretty<'_> {
32 self.borrow().pretty()
33 }
34}
35
36impl<T: Display + 'static> AntichainExt for MutableAntichain<T> {
37 type Pretty<'a> = FrontierPrinter<AntichainRef<'a, T>>;
38
39 fn pretty(&self) -> Self::Pretty<'_> {
40 self.frontier().pretty()
41 }
42}
43
44impl<'a, T: Display> AntichainExt for AntichainRef<'a, T> {
45 type Pretty<'b>
46 = FrontierPrinter<Self>
47 where
48 Self: 'b;
49
50 fn pretty(&self) -> Self::Pretty<'a> {
51 FrontierPrinter(*self)
52 }
53}
54
55pub struct FrontierPrinter<F>(F);
56
57impl<'a, T: Display> Display for FrontierPrinter<AntichainRef<'a, T>> {
58 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
59 f.write_str("{")?;
60 let mut time_iter = self.0.iter();
61 if let Some(t) = time_iter.next() {
62 t.fmt(f)?;
63 }
64 for t in time_iter {
65 f.write_str(", ")?;
66 t.fmt(f)?;
67 }
68 f.write_str("}")?;
69 Ok(())
70 }
71}