31 lines
570 B
Rust
31 lines
570 B
Rust
use std::rc::Rc;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum Value {
|
|
Int(i32),
|
|
String(Rc<str>),
|
|
Null,
|
|
}
|
|
|
|
impl Default for Value {
|
|
fn default() -> Value {
|
|
Value::Null
|
|
}
|
|
}
|
|
|
|
impl Value {
|
|
pub fn unwrap_int(&self) -> i32 {
|
|
match self {
|
|
Value::Int(i) => *i,
|
|
_ => panic!("Attempt to unwrap Int; found {:?}", self),
|
|
}
|
|
}
|
|
|
|
pub fn unwrap_string(&self) -> &Rc<str> {
|
|
match self {
|
|
Value::String(s) => s,
|
|
_ => panic!("Attempt to unwrap String; found {:?}", self),
|
|
}
|
|
}
|
|
}
|