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
#[derive(Debug, PartialEq, Eq)]
pub enum Name {
    Available(String),
    Unavailable,
}

impl Name {
    pub fn available(name: impl ToString) -> Self {
        Self::Available(name.to_string())
    }
}

impl std::fmt::Display for Name {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Available(name) => name.fmt(f),
            Self::Unavailable => write!(f, "(not available)"),
        }
    }
}

impl<T> From<Option<T>> for Name
where
    T: ToString,
{
    fn from(name: Option<T>) -> Self {
        match name {
            Some(name) => Self::available(name),
            None => Self::Unavailable,
        }
    }
}