1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! A module with a utility enum [`EitherString`].

/// Either allocated string or some type which can be used as a string.
#[derive(Debug)]
pub enum EitherString<T> {
    /// Allocated string.
    Owned(String),
    /// Something which can be used as a string.
    Some(T),
}

impl<T> AsRef<str> for EitherString<T>
where
    T: AsRef<str>,
{
    fn as_ref(&self) -> &str {
        match self {
            EitherString::Owned(s) => s.as_ref(),
            EitherString::Some(s) => s.as_ref(),
        }
    }
}