Skip to main content

quorum_set/progress/
display_vec_progress.rs

1use std::fmt::Debug;
2use std::fmt::Display;
3use std::fmt::Formatter;
4
5use super::VecProgressEntry;
6use super::vec_progress::VecProgress;
7use crate::quorum::QuorumSet;
8
9/// Display adapter returned by [`VecProgress::display_with`].
10pub struct DisplayVecProgress<'a, Entry, QS, Fmt>
11where
12    Entry: VecProgressEntry,
13    Entry::Id: Ord + Clone + Debug,
14    Entry::Progress: Debug,
15    QS: QuorumSet<Id = Entry::Id>,
16    Fmt: Fn(&mut Formatter<'_>, &Entry) -> std::fmt::Result,
17{
18    pub(crate) inner: &'a VecProgress<Entry, QS>,
19    pub(crate) f: Fmt,
20}
21
22impl<Entry, QS, Fmt> Display for DisplayVecProgress<'_, Entry, QS, Fmt>
23where
24    Entry: VecProgressEntry,
25    Entry::Id: Ord + Clone + Debug,
26    Entry::Progress: Debug,
27    QS: QuorumSet<Id = Entry::Id>,
28    Fmt: Fn(&mut Formatter<'_>, &Entry) -> std::fmt::Result,
29{
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        write!(f, "{{")?;
32        for (i, item) in self.inner.iter().enumerate() {
33            if i > 0 {
34                write!(f, ", ")?;
35            }
36            (self.f)(f, item)?;
37        }
38        write!(f, "}}")?;
39
40        Ok(())
41    }
42}