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
54
55
56
57
58
use std::error::Error;
use std::fmt::Display;
use std::sync::Arc;
use std::borrow::Borrow;

#[inline]
pub fn identity<T>(t: T) -> T {
    t
}

#[derive(Clone, Debug)]
pub struct ArcStr(Arc<str>);

impl ArcStr {
    #[inline]
    pub fn from(f: &str) -> ArcStr {
        ArcStr(Arc::from(f.trim_end_matches('\n')))
    }
}

impl Borrow<str> for ArcStr {
    fn borrow(&self) -> &str {
        self.0.borrow()
    }
}

impl Borrow<[u8]> for ArcStr {
    fn borrow(&self) -> &[u8] {
        self.0.as_bytes()
    }
}

impl Borrow<Arc<str>> for ArcStr {
    fn borrow(&self) -> &Arc<str> {
        &self.0
    }
}

pub trait Runner {
    fn gen(input: ArcStr) -> Self
    where
        Self: Sized;

    fn run(&self) -> Box<dyn Display>;

    fn bench(&self, black_box: fn(&dyn Display));

    fn try_gen(input: ArcStr) -> Result<Self, Box<dyn Error>>
    where
        Self: Sized,
    {
        Ok(Self::gen(input))
    }

    fn try_run(&self) -> Result<Box<dyn Display>, Box<dyn Error>> {
        Ok(self.run())
    }
}