use slotmap::new_key_type;
use std::fmt;
pub type DocumentId = u32;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct NameId(pub u32);
impl fmt::Debug for NameId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "NameId({})", self.0)
}
}
impl fmt::Display for NameId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "${}", self.0)
}
}
new_key_type! {
pub struct SimpleTypeKey;
pub struct ComplexTypeKey;
pub struct ElementKey;
pub struct AttributeKey;
pub struct AttributeGroupKey;
pub struct ModelGroupKey;
pub struct NotationKey;
pub struct IdentityConstraintKey;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TypeKey {
Simple(SimpleTypeKey),
Complex(ComplexTypeKey),
}
impl TypeKey {
pub fn as_simple(&self) -> Option<SimpleTypeKey> {
match self {
TypeKey::Simple(key) => Some(*key),
_ => None,
}
}
pub fn as_complex(&self) -> Option<ComplexTypeKey> {
match self {
TypeKey::Complex(key) => Some(*key),
_ => None,
}
}
}
impl From<SimpleTypeKey> for TypeKey {
fn from(key: SimpleTypeKey) -> Self {
TypeKey::Simple(key)
}
}
impl From<ComplexTypeKey> for TypeKey {
fn from(key: ComplexTypeKey) -> Self {
TypeKey::Complex(key)
}
}