cuddle_please_misc/
ui.rs

1pub trait Ui {
2    fn write_str(&self, content: &str);
3    fn write_err_str(&self, content: &str);
4
5    fn write_str_ln(&self, content: &str);
6    fn write_err_str_ln(&self, content: &str);
7}
8
9pub type DynUi = Box<dyn Ui + Send + Sync>;
10
11impl Default for DynUi {
12    fn default() -> Self {
13        Box::<ConsoleUi>::default()
14    }
15}
16
17#[derive(Default)]
18pub struct ConsoleUi {}
19
20#[allow(dead_code)]
21impl ConsoleUi {
22    pub fn new() -> Self {
23        Self::default()
24    }
25}
26
27impl From<ConsoleUi> for DynUi {
28    fn from(value: ConsoleUi) -> Self {
29        Box::new(value)
30    }
31}
32
33impl Ui for ConsoleUi {
34    fn write_str(&self, content: &str) {
35        print!("{}", content)
36    }
37
38    fn write_err_str(&self, content: &str) {
39        eprint!("{}", content)
40    }
41
42    fn write_str_ln(&self, content: &str) {
43        println!("{}", content)
44    }
45
46    fn write_err_str_ln(&self, content: &str) {
47        eprintln!("{}", content)
48    }
49}