tinc/private/
expected.rs

1use std::collections::{BTreeMap, HashMap};
2
3pub trait Expected {
4    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result;
5}
6
7impl<V: Expected> Expected for Box<V> {
8    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
9        V::expecting(formatter)
10    }
11}
12
13impl<V: Expected> Expected for Option<V> {
14    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
15        write!(formatter, "an optional `")?;
16        V::expecting(formatter)?;
17        write!(formatter, "`")
18    }
19}
20
21impl<V: Expected> Expected for Vec<V> {
22    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
23        write!(formatter, "a sequence of `")?;
24        V::expecting(formatter)?;
25        write!(formatter, "`s")
26    }
27}
28
29impl<K: Expected, V: Expected> Expected for BTreeMap<K, V> {
30    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
31        write!(formatter, "a map of `")?;
32        K::expecting(formatter)?;
33        write!(formatter, "`s to `")?;
34        V::expecting(formatter)?;
35        write!(formatter, "`s")
36    }
37}
38
39impl<K: Expected, V: Expected, S> Expected for HashMap<K, V, S> {
40    fn expecting(formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
41        write!(formatter, "a map of `")?;
42        K::expecting(formatter)?;
43        write!(formatter, "`s to `")?;
44        V::expecting(formatter)?;
45        write!(formatter, "`s")
46    }
47}