use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
pub struct I32Entity(i32);
impl I32Entity {
pub fn new(value: i32) -> Self {
Self(value)
}
pub fn add(&self, rhs: &Self) -> Self {
Self(self.0 + rhs.0)
}
}
impl Debug for I32Entity {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{}", self.0)
}
}
impl Display for I32Entity {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{}", self.0)
}
}
pub struct StrEntity(String);
impl StrEntity {
pub fn new(value: String) -> Self {
Self(value)
}
}
impl Debug for StrEntity {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{}", self.0)
}
}
impl Display for StrEntity {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{}", self.0)
}
}
#[derive(Debug)]
pub enum RuntimeTypeInfo {
Addr,
I32,
Str,
}
impl Display for RuntimeTypeInfo {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"{}",
match self {
RuntimeTypeInfo::Addr => "addr",
RuntimeTypeInfo::I32 => "i32",
RuntimeTypeInfo::Str => "str",
}
)
}
}
#[derive(Debug)]
pub enum Entity {
Addr(usize),
I32(I32Entity),
Str(StrEntity),
}
impl Entity {
pub fn get_type(&self) -> RuntimeTypeInfo {
match self {
Entity::Addr(_) => RuntimeTypeInfo::Addr,
Entity::I32(_) => RuntimeTypeInfo::I32,
Entity::Str(_) => RuntimeTypeInfo::Str,
}
}
}