2020-06-16 20:00:11 -04:00
|
|
|
use std::fmt;
|
2020-05-31 04:51:41 -04:00
|
|
|
|
|
|
|
/// The selector namespace.
|
|
|
|
///
|
|
|
|
/// If this is `None`, this matches all elements in the default namespace. If
|
|
|
|
/// it's `Empty`, this matches all elements that aren't in any
|
|
|
|
/// namespace. If it's `Asterisk`, this matches all elements in any namespace.
|
|
|
|
/// Otherwise, it matches all elements in the given namespace.
|
2020-06-07 03:06:08 -04:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
2020-05-31 04:51:41 -04:00
|
|
|
pub(crate) enum Namespace {
|
|
|
|
Empty,
|
|
|
|
Asterisk,
|
|
|
|
Other(String),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
2020-06-16 20:00:11 -04:00
|
|
|
impl fmt::Display for Namespace {
|
2020-05-31 04:51:41 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::Empty => write!(f, "|"),
|
|
|
|
Self::Asterisk => write!(f, "*|"),
|
|
|
|
Self::Other(namespace) => write!(f, "{}|", namespace),
|
|
|
|
Self::None => Ok(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 03:06:08 -04:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
2020-05-31 04:51:41 -04:00
|
|
|
pub(crate) struct QualifiedName {
|
|
|
|
pub ident: String,
|
|
|
|
pub namespace: Namespace,
|
|
|
|
}
|
|
|
|
|
2020-06-16 20:00:11 -04:00
|
|
|
impl fmt::Display for QualifiedName {
|
2020-05-31 04:51:41 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.namespace)?;
|
|
|
|
f.write_str(&self.ident)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 03:06:08 -04:00
|
|
|
pub(crate) struct Specificity {
|
|
|
|
pub min: i32,
|
|
|
|
pub max: i32,
|
|
|
|
}
|
2020-05-31 04:51:41 -04:00
|
|
|
|
|
|
|
impl Specificity {
|
2020-06-07 03:06:08 -04:00
|
|
|
pub const fn new(min: i32, max: i32) -> Self {
|
|
|
|
Specificity { min, max }
|
2020-05-31 04:51:41 -04:00
|
|
|
}
|
|
|
|
}
|