use crate::ast::node::expression::Expression; #[derive(Debug)] pub struct DString(Vec>); impl DString { pub fn new(parts: Vec>) -> Self { Self(parts) } pub fn parts(&self) -> Vec<&DStringPart> { self.0.iter().map(Box::as_ref).collect() } pub fn parts_mut(&mut self) -> Vec<&mut DStringPart> { self.0.iter_mut().map(Box::as_mut).collect() } } #[derive(Debug)] pub enum DStringPart { String(String), Expression(Box), } impl DStringPart { pub fn from_string(s: &str) -> DStringPart { DStringPart::String(String::from(s)) } pub fn from_expression(e: Expression) -> DStringPart { DStringPart::Expression(Box::new(e)) } pub fn is_string(&self) -> bool { match self { DStringPart::String(_) => true, _ => false, } } pub fn unwrap_string(self) -> String { match self { DStringPart::String(s) => s, _ => panic!(), } } pub fn is_expression(&self) -> bool { match self { DStringPart::Expression(_) => true, _ => false, } } }