#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum NSChoice<'a> {
None,
OneOf(&'a str),
AnyOf(&'a [&'a str]),
Any,
}
impl<'a> From<&'a str> for NSChoice<'a> {
fn from(ns: &'a str) -> NSChoice<'a> {
NSChoice::OneOf(ns)
}
}
impl<'a> From<Option<&'a str>> for NSChoice<'a> {
fn from(ns: Option<&'a str>) -> Self {
match ns {
None => NSChoice::Any,
Some(ns) => ns.into()
}
}
}
impl<'a> NSChoice<'a> {
pub(crate) fn compare(&self, ns: &Option<String>) -> bool {
match (ns, &self) {
(Some(_), NSChoice::None) => false,
(None, NSChoice::None) => false,
(_, NSChoice::Any) => true,
(Some(ns), NSChoice::OneOf(wanted_ns)) => &ns == wanted_ns,
(Some(ns), NSChoice::AnyOf(wanted_nss)) => wanted_nss.iter().any(|w| &ns == w),
(None, _) => false
}
}
}