1
use std::fmt;
2

            
3
use itertools::Itertools;
4
use oxidd::bdd::BDDFunction;
5
use oxidd::util::OptBool;
6

            
7
use crate::CubeIter;
8

            
9
/// A helper structure to format configuration sets for output.
10
pub struct FormatConfigSet<'a>(pub &'a BDDFunction);
11

            
12
impl fmt::Display for FormatConfigSet<'_> {
13
100
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14
100
        write!(
15
100
            f,
16
            "{}",
17
3185
            CubeIter::new(self.0).format_with("+", |cube, fmt| {
18
3185
                fmt(&format_args!("{}", FormatConfig(&cube.map_err(|_| fmt::Error)?.0)))
19
3185
            })
20
        )
21
100
    }
22
}
23

            
24
/// A helper structure to format a configuration for output.
25
pub struct FormatConfig<'a>(pub &'a Vec<OptBool>);
26

            
27
impl fmt::Display for FormatConfig<'_> {
28
6561
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29
45545
        for value in self.0 {
30
45545
            match value {
31
17499
                OptBool::True => write!(f, "1")?,
32
26919
                OptBool::False => write!(f, "0")?,
33
1127
                OptBool::None => write!(f, "-")?,
34
            }
35
        }
36

            
37
6561
        Ok(())
38
6561
    }
39
}