pub(crate) struct NullDescriptor;
pub(crate) struct NamedDescriptor {
pub(crate) name: &'static str,
}
pub(crate) struct NumberDescriptor {
pub(crate) name: &'static str,
pub(crate) precision: usize,
}
pub(crate) struct UnorderedNamedDescriptor {
pub(crate) name: &'static str,
}
pub trait Descriptor {
fn name(&self) -> Option<&str> {
None
}
fn precision(&self) -> Option<usize> {
None
}
fn unordered(&self) -> bool {
false
}
}
impl Descriptor for NullDescriptor {}
impl Descriptor for NamedDescriptor {
fn name(&self) -> Option<&str> {
Some(self.name)
}
}
impl Descriptor for NumberDescriptor {
fn name(&self) -> Option<&str> {
Some(self.name)
}
fn precision(&self) -> Option<usize> {
if self.precision > 0 {
Some(self.precision)
} else {
None
}
}
}
impl Descriptor for UnorderedNamedDescriptor {
fn name(&self) -> Option<&str> {
Some(self.name)
}
fn unordered(&self) -> bool {
true
}
}