xsd_parser/types/info/
enumeration.rsuse std::ops::{Deref, DerefMut};
use crate::schema::xs::Use;
use crate::types::{Ident, TypeEq, Types};
use super::Base;
#[derive(Default, Debug, Clone)]
pub struct EnumerationInfo {
pub base: Base,
pub variants: VariantsInfo,
}
#[derive(Debug, Clone)]
pub struct VariantInfo {
pub ident: Ident,
pub use_: Use,
pub type_: Option<Ident>,
}
#[derive(Default, Debug, Clone)]
pub struct VariantsInfo(Vec<VariantInfo>);
impl TypeEq for EnumerationInfo {
fn type_eq(&self, other: &Self, types: &Types) -> bool {
let Self { base, variants } = self;
base.type_eq(&other.base, types) && variants.type_eq(&other.variants, types)
}
}
impl VariantInfo {
#[must_use]
pub fn new(ident: Ident) -> Self {
Self {
ident,
use_: Use::Optional,
type_: None,
}
}
#[must_use]
pub fn with_type(mut self, type_: Option<Ident>) -> Self {
self.type_ = type_;
self
}
}
impl TypeEq for VariantInfo {
fn type_eq(&self, other: &Self, types: &Types) -> bool {
let Self { ident, use_, type_ } = self;
ident.eq(&other.ident) && use_.eq(&other.use_) && type_.type_eq(&other.type_, types)
}
}
impl Deref for VariantsInfo {
type Target = Vec<VariantInfo>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for VariantsInfo {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl TypeEq for VariantsInfo {
fn type_eq(&self, other: &Self, types: &Types) -> bool {
TypeEq::type_eq_iter(self.0.iter(), other.0.iter(), types)
}
}