Files
rust-interpreter/src/object/mod.rs
T
Yann Ahlgrim 5869d8acc2 evaluator
2026-07-11 20:25:22 +02:00

51 lines
784 B
Rust

pub enum ObjectType {
INTEGER,
BOOLEAN,
NULL,
}
pub trait Object {
fn object_type(&self) -> ObjectType;
fn inspect(&self) -> String;
}
pub struct Integer {
pub value: i64,
}
impl Object for Integer {
fn object_type(&self) -> ObjectType {
ObjectType::INTEGER
}
fn inspect(&self) -> String {
self.value.to_string()
}
}
pub struct Boolean {
pub value: bool,
}
impl Object for Boolean {
fn object_type(&self) -> ObjectType {
ObjectType::BOOLEAN
}
fn inspect(&self) -> String {
self.value.to_string()
}
}
pub struct Null;
impl Object for Null {
fn object_type(&self) -> ObjectType {
ObjectType::NULL
}
fn inspect(&self) -> String {
"null".to_string()
}
}