use std::hash::{Hash, Hasher};
use crate::models::TypeIdent;
use super::{Constrains, MetaTypes, TypeEq};
#[derive(Debug, Clone)]
pub struct SimpleMeta {
pub base: TypeIdent,
pub is_list: bool,
pub constrains: Constrains,
}
#[derive(Default, Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub enum WhiteSpace {
#[default]
Preserve,
Replace,
Collapse,
}
impl SimpleMeta {
#[must_use]
pub fn new(base: TypeIdent) -> Self {
Self {
base,
is_list: false,
constrains: Constrains::default(),
}
}
}
impl TypeEq for SimpleMeta {
fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
let Self {
base,
is_list,
constrains,
} = self;
base.type_hash(hasher, types);
is_list.hash(hasher);
constrains.hash(hasher);
}
fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
let Self {
base,
is_list,
constrains,
} = self;
base.type_eq(&other.base, types)
&& is_list.eq(&other.is_list)
&& constrains.eq(&other.constrains)
}
}
impl TypeEq for WhiteSpace {
fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
let _types = types;
self.hash(hasher);
}
fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
let _types = types;
self.eq(other)
}
}