1 | //! A module with a utility enum [`EitherString`]. |
2 | |
3 | /// Either allocated string or some type which can be used as a string. |
4 | #[derive (Debug)] |
5 | pub enum EitherString<T> { |
6 | /// Allocated string. |
7 | Owned(String), |
8 | /// Something which can be used as a string. |
9 | Some(T), |
10 | } |
11 | |
12 | impl<T> AsRef<str> for EitherString<T> |
13 | where |
14 | T: AsRef<str>, |
15 | { |
16 | fn as_ref(&self) -> &str { |
17 | match self { |
18 | EitherString::Owned(s: &String) => s.as_ref(), |
19 | EitherString::Some(s: &T) => s.as_ref(), |
20 | } |
21 | } |
22 | } |
23 | |