use std::hash::{Hash, Hasher};
use crate::models::TypeIdent;
use super::{MetaTypes, TypeEq};
#[derive(Default, Debug, Clone)]
pub struct DynamicMeta {
pub type_: Option<TypeIdent>,
pub derived_types: Vec<DerivedTypeMeta>,
}
#[derive(Debug, Clone)]
pub struct DerivedTypeMeta {
pub type_: TypeIdent,
pub display_name: Option<String>,
}
impl TypeEq for DynamicMeta {
fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
let Self {
type_,
derived_types,
} = self;
type_.type_hash(hasher, types);
TypeEq::type_hash_slice(derived_types, hasher, types);
}
fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
let Self {
type_,
derived_types,
} = self;
type_.type_eq(&other.type_, types)
&& TypeEq::type_eq_iter(derived_types.iter(), other.derived_types.iter(), types)
}
}
impl DerivedTypeMeta {
#[must_use]
pub fn new(type_: TypeIdent) -> Self {
Self {
type_,
display_name: None,
}
}
}
impl TypeEq for DerivedTypeMeta {
fn type_hash<H: Hasher>(&self, hasher: &mut H, types: &MetaTypes) {
let Self {
type_,
display_name,
} = self;
type_.type_hash(hasher, types);
display_name.hash(hasher);
}
fn type_eq(&self, other: &Self, types: &MetaTypes) -> bool {
let Self {
type_,
display_name,
} = self;
type_.type_eq(&other.type_, types) && display_name == &other.display_name
}
}