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
use crate::*;

pub static ERRORS: Lazy<AtomicRefCell<Errors>> =
    Lazy::new(|| AtomicRefCell::new(Errors::new()));

pub struct Errors {
    pub data: HashMap<Cow<'static, str>, Cow<'static, str>>,
}

impl Errors {
    pub fn new() -> Self {
        Self { data: HashMap::new() }
    }
}

pub fn report_error(
    id: impl Into<Cow<'static, str>>,
    error: impl Into<Cow<'static, str>>,
) {
    ERRORS.borrow_mut().data.insert(id.into(), error.into());
}

// pub fn reported_errors_iter(
// ) -> impl Deref<Target = impl Iterator<Item = (&Cow<'static, str>, &Cow<'static, str>)>>
// {
//     AtomicRef::map(ERRORS.borrow(), |x| x.data.iter())
// }