1use contextual::{DisplayWithContext, WithContext};
2
3pub trait Handler<N, W> {
9 fn handle(&mut self, vocabulary: &N, warning: W);
11}
12
13impl<N, W> Handler<N, W> for () {
14 fn handle(&mut self, _vocabulary: &N, _warning: W) {}
15}
16
17impl<'a, N, W, H: Handler<N, W>> Handler<N, W> for &'a mut H {
18 fn handle(&mut self, vocabulary: &N, warning: W) {
19 H::handle(*self, vocabulary, warning)
20 }
21}
22
23pub struct Print;
26
27impl<N, W: std::fmt::Display> Handler<N, W> for Print {
28 fn handle(&mut self, _vocabulary: &N, warning: W) {
29 eprintln!("{warning}")
30 }
31}
32
33pub struct PrintWith;
35
36impl<N, W: DisplayWithContext<N>> Handler<N, W> for PrintWith {
37 fn handle(&mut self, vocabulary: &N, warning: W) {
38 eprintln!("{}", warning.with(vocabulary))
39 }
40}