aoc_runner/
lib.rs

1use std::borrow::Borrow;
2use std::error::Error;
3use std::fmt::Display;
4use std::sync::Arc;
5
6#[inline]
7pub fn identity<T>(t: T) -> T {
8    t
9}
10
11#[derive(Clone, Debug)]
12pub struct ArcStr(Arc<str>);
13
14impl ArcStr {
15    #[inline]
16    pub fn from(f: &str) -> ArcStr {
17        ArcStr(Arc::from(f.trim_end_matches('\n')))
18    }
19}
20
21impl Borrow<str> for ArcStr {
22    fn borrow(&self) -> &str {
23        self.0.borrow()
24    }
25}
26
27impl Borrow<[u8]> for ArcStr {
28    fn borrow(&self) -> &[u8] {
29        self.0.as_bytes()
30    }
31}
32
33impl Borrow<Arc<str>> for ArcStr {
34    fn borrow(&self) -> &Arc<str> {
35        &self.0
36    }
37}
38
39pub trait Runner {
40    fn gen(input: ArcStr) -> Self
41    where
42        Self: Sized;
43
44    fn run(&self) -> Box<dyn Display>;
45
46    fn bench(&self, black_box: fn(&dyn Display));
47
48    fn try_gen(input: ArcStr) -> Result<Self, Box<dyn Error>>
49    where
50        Self: Sized,
51    {
52        Ok(Self::gen(input))
53    }
54
55    fn try_run(&self) -> Result<Box<dyn Display>, Box<dyn Error>> {
56        Ok(self.run())
57    }
58}