Add table expression constructor

This commit is contained in:
numzero 2025-04-19 15:13:48 +03:00
parent ead7ac054d
commit b131d40702

View File

@ -88,6 +88,17 @@ impl Expression {
pub fn new_variable(name: impl Into<String>) -> Self { pub fn new_variable(name: impl Into<String>) -> Self {
Self::Variable(Location::new_variable(name)) Self::Variable(Location::new_variable(name))
} }
pub fn new_table<'a>(fields: impl Iterator<Item = (&'a str, Expression)>) -> Self {
Self::Table(Table {
fields: fields
.map(|(key, value)| Field {
name: Expression::new_constant(key),
init: value,
})
.collect(),
})
}
} }
impl From<()> for Constant { impl From<()> for Constant {