use std::{any::Any, fmt::Display, sync::Arc}; use crate::info::DisplayInfo; use super::{MersData, MersType, Type}; #[derive(Debug, Clone)] pub struct String(pub std::string::String); impl MersData for String { fn display(&self, _info: &DisplayInfo<'_>, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{self}") } fn is_eq(&self, other: &dyn MersData) -> bool { if let Some(other) = other.as_any().downcast_ref::() { other.0 == self.0 } else { false } } fn clone(&self) -> Box { Box::new(Clone::clone(self)) } fn as_any(&self) -> &dyn Any { self } fn as_type(&self) -> super::Type { Type::new(StringT) } fn mut_any(&mut self) -> &mut dyn Any { self } fn to_any(self) -> Box { Box::new(self) } } #[derive(Debug, Clone)] pub struct StringT; impl MersType for StringT { fn display( &self, _info: &crate::info::DisplayInfo<'_>, f: &mut std::fmt::Formatter, ) -> std::fmt::Result { write!(f, "{self}") } fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { acc.add(Arc::new(self.clone())); } fn as_any(&self) -> &dyn Any { self } fn mut_any(&mut self) -> &mut dyn Any { self } fn to_any(self) -> Box { Box::new(self) } } impl Display for String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl Display for StringT { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "String") } }