mers/mers_lib/src/data/float.rs

63 lines
1.4 KiB
Rust
Raw Normal View History

2023-07-28 00:33:15 +02:00
use std::{any::Any, fmt::Display};
use super::{MersData, MersType, Type};
#[derive(Debug, Clone)]
pub struct Float(pub f64);
impl MersData for Float {
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))
}
2023-08-14 17:17:08 +02:00
fn as_type(&self) -> super::Type {
Type::new(FloatT)
}
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)
}
}
#[derive(Debug)]
pub struct FloatT;
impl MersType for FloatT {
fn is_same_type_as(&self, other: &dyn MersType) -> bool {
other.as_any().downcast_ref::<Self>().is_some()
}
fn is_included_in_single(&self, target: &dyn MersType) -> bool {
self.is_same_type_as(target)
}
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 Float {
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 FloatT {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Float")
}
}