xsd_parser/types/info/
element.rsuse std::ops::{Deref, DerefMut};
use crate::schema::{MaxOccurs, MinOccurs};
use crate::types::{Ident, TypeEq, Types};
#[derive(Debug, Clone)]
pub struct ElementInfo {
pub ident: Ident,
pub type_: Ident,
pub min_occurs: MinOccurs,
pub max_occurs: MaxOccurs,
pub element_mode: ElementMode,
}
#[derive(Default, Debug, Clone)]
pub struct ElementsInfo(pub Vec<ElementInfo>);
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ElementMode {
Element,
Group,
}
impl ElementInfo {
#[must_use]
pub fn new(ident: Ident, type_: Ident, element_mode: ElementMode) -> Self {
Self {
ident,
type_,
element_mode,
min_occurs: 1,
max_occurs: MaxOccurs::Bounded(1),
}
}
}
impl TypeEq for ElementInfo {
fn type_eq(&self, other: &Self, types: &Types) -> bool {
let Self {
ident,
type_,
element_mode,
min_occurs,
max_occurs,
} = self;
ident.eq(&other.ident)
&& type_.type_eq(&other.type_, types)
&& element_mode.eq(&other.element_mode)
&& min_occurs.eq(&other.min_occurs)
&& max_occurs.eq(&other.max_occurs)
}
}
impl Deref for ElementsInfo {
type Target = Vec<ElementInfo>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for ElementsInfo {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl TypeEq for ElementsInfo {
fn type_eq(&self, other: &Self, types: &Types) -> bool {
TypeEq::type_eq_iter(self.0.iter(), other.0.iter(), types)
}
}