use std::borrow::Cow;
#[derive(Debug, Eq, PartialEq)]
pub struct Name {
pub(crate) attributes: Vec<NameAttribute<'static>>,
pub(crate) delimiter: Option<&'static str>,
pub(crate) name: &'static str,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum NameAttribute<'a> {
NoInferiors,
NoSelect,
Marked,
Unmarked,
Custom(Cow<'a, str>),
}
impl NameAttribute<'static> {
fn system(s: &str) -> Option<Self> {
match s {
"\\Noinferiors" => Some(NameAttribute::NoInferiors),
"\\Noselect" => Some(NameAttribute::NoSelect),
"\\Marked" => Some(NameAttribute::Marked),
"\\Unmarked" => Some(NameAttribute::Unmarked),
_ => None,
}
}
}
impl<'a> From<String> for NameAttribute<'a> {
fn from(s: String) -> Self {
if let Some(f) = NameAttribute::system(&s) {
f
} else {
NameAttribute::Custom(Cow::Owned(s))
}
}
}
impl<'a> From<&'a str> for NameAttribute<'a> {
fn from(s: &'a str) -> Self {
if let Some(f) = NameAttribute::system(s) {
f
} else {
NameAttribute::Custom(Cow::Borrowed(s))
}
}
}
impl Name {
pub fn attributes(&self) -> &[NameAttribute<'_>] {
&self.attributes[..]
}
pub fn delimiter(&self) -> Option<&str> {
self.delimiter
}
pub fn name(&self) -> &str {
self.name
}
}