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