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
250
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14
250
        write!(
15
250
            f,
16
            "{}",
17
3341
            CubeIter::new(self.0).format_with("+", |cube, fmt| {
18
3341
                fmt(&format_args!("{}", FormatConfig(&cube.map_err(|_| fmt::Error)?.0)))
19
3341
            })
20
        )
21
250
    }
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
6692
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29
45894
        for value in self.0 {
30
45894
            match value {
31
17661
                OptBool::True => write!(f, "1")?,
32
26881
                OptBool::False => write!(f, "0")?,
33
1352
                OptBool::None => write!(f, "-")?,
34
            }
35
        }
36

            
37
6692
        Ok(())
38
6692
    }
39
}