2023-10-24 09:31:49 +02:00
|
|
|
use std::{any::Any, fmt::Display, sync::Arc};
|
2023-07-28 00:33:15 +02:00
|
|
|
|
2024-09-28 01:51:20 +02:00
|
|
|
use crate::info::DisplayInfo;
|
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
use super::{MersData, MersType, Type};
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct String(pub std::string::String);
|
|
|
|
|
|
|
|
impl MersData for String {
|
2024-09-28 01:51:20 +02:00
|
|
|
fn display(&self, _info: &DisplayInfo<'_>, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
write!(f, "{self}")
|
|
|
|
}
|
2023-08-14 17:17:08 +02:00
|
|
|
fn is_eq(&self, other: &dyn MersData) -> bool {
|
|
|
|
if let Some(other) = other.as_any().downcast_ref::<Self>() {
|
|
|
|
other.0 == self.0
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 00:33:15 +02:00
|
|
|
fn clone(&self) -> Box<dyn MersData> {
|
|
|
|
Box::new(Clone::clone(self))
|
|
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
self
|
|
|
|
}
|
2023-08-14 17:17:08 +02:00
|
|
|
fn as_type(&self) -> super::Type {
|
|
|
|
Type::new(StringT)
|
|
|
|
}
|
2023-07-28 00:33:15 +02:00
|
|
|
fn mut_any(&mut self) -> &mut dyn Any {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
fn to_any(self) -> Box<dyn Any> {
|
|
|
|
Box::new(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 09:31:49 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2023-07-28 00:33:15 +02:00
|
|
|
pub struct StringT;
|
|
|
|
impl MersType for StringT {
|
2024-09-28 01:51:20 +02:00
|
|
|
fn display(
|
|
|
|
&self,
|
|
|
|
_info: &crate::info::DisplayInfo<'_>,
|
|
|
|
f: &mut std::fmt::Formatter,
|
|
|
|
) -> std::fmt::Result {
|
|
|
|
write!(f, "{self}")
|
|
|
|
}
|
2023-07-28 00:33:15 +02:00
|
|
|
fn is_same_type_as(&self, other: &dyn MersType) -> bool {
|
|
|
|
other.as_any().downcast_ref::<Self>().is_some()
|
|
|
|
}
|
2024-04-16 13:38:50 +02:00
|
|
|
fn is_included_in(&self, target: &dyn MersType) -> bool {
|
2023-07-28 00:33:15 +02:00
|
|
|
self.is_same_type_as(target)
|
|
|
|
}
|
2023-10-24 09:31:49 +02:00
|
|
|
fn subtypes(&self, acc: &mut Type) {
|
|
|
|
acc.add(Arc::new(self.clone()));
|
|
|
|
}
|
2023-07-28 00:33:15 +02:00
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
fn mut_any(&mut self) -> &mut dyn Any {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
fn to_any(self) -> Box<dyn Any> {
|
|
|
|
Box::new(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for String {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 17:17:08 +02:00
|
|
|
impl Display for StringT {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "String")
|
|
|
|
}
|
|
|
|
}
|