1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mod info;
mod validate;

use crate::info::Info;
use crate::validate::Validate;
use crossterm::style::Stylize;
use solp::Consume;

extern crate humantime;
extern crate solp;
#[macro_use]
extern crate prettytable;
extern crate crossterm;

pub trait ConsumeDisplay: Consume + std::fmt::Display {
    fn as_consume(&mut self) -> &mut dyn Consume;
}

// Trait casting code begin

impl ConsumeDisplay for Info {
    fn as_consume(&mut self) -> &mut dyn Consume {
        self
    }
}

impl ConsumeDisplay for Validate {
    fn as_consume(&mut self) -> &mut dyn Consume {
        self
    }
}

// Trait casting code end

// Factory method
pub fn new_consumer(
    debug: bool,
    only_validate: bool,
    only_problems: bool,
) -> Box<dyn ConsumeDisplay> {
    if only_validate {
        Validate::new_box(debug, only_problems)
    } else {
        Info::new_box(debug)
    }
}

fn err(debug: bool, path: &str) {
    if debug {
        return;
    }
    eprintln!("Error parsing {} solution", path.red());
}