51 lines
784 B
Rust
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()
|
|
}
|
|
}
|