//! Runtime values (Phase I). use std::fmt; #[derive(Debug, Clone, PartialEq)] pub enum Value { None, Bool(bool), Int(i64), Text(String), /// Single-column table rows (v0); multi-column later. List(Vec), } impl Value { pub fn truthy(&self) -> bool { match self { Value::None => false, Value::Bool(b) => *b, Value::Int(n) => *n != 0, Value::Text(s) => !s.is_empty(), Value::List(xs) => !xs.is_empty(), } } pub fn as_display(&self) -> String { match self { Value::None => "None".into(), Value::Bool(true) => "True".into(), Value::Bool(false) => "False".into(), Value::Int(n) => n.to_string(), Value::Text(s) => s.clone(), Value::List(_) => "".into(), } } } impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.as_display()) } }