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
#[derive(Debug, Clone, Hash)]
pub enum ParsedString<'a> {
    Borrowed(&'a str),
    Owned(String),
}
impl<'a> From<String> for ParsedString<'a> {
    fn from(t: String) -> Self {
        ParsedString::Owned(t)
    }
}
impl<'a> From<&'a str> for ParsedString<'a> {
    fn from(s: &'a str) -> Self {
        ParsedString::Borrowed(s)
    }
}
impl<'a> std::fmt::Display for ParsedString<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ParsedString::Borrowed(s) => write!(f, "{}", s), // TODO escape
            ParsedString::Owned(s) => write!(f, "{}", s),
        }
    }
}
impl<'a> Eq for ParsedString<'a> {}
// TODO do not use std::fmt::Display for Eq, PartialEq
impl<'a, Rhs: std::fmt::Display> PartialEq<Rhs> for ParsedString<'a> {
    fn eq(&self, other: &Rhs) -> bool {
        match self {
            ParsedString::Borrowed(s) => *s == other.to_string(),
            ParsedString::Owned(s) => *s == other.to_string(),
        }
    }
}