1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
use crate::nodes::Expression; #[derive(Clone, Debug, PartialEq, Eq)] pub struct LocalAssignStatement { variables: Vec<String>, values: Vec<Expression>, } impl LocalAssignStatement { pub fn new(variables: Vec<String>, values: Vec<Expression>) -> Self { Self { variables, values, } } pub fn from_variable<S: Into<String>>(variable: S) -> Self { Self { variables: vec![variable.into()], values: Vec::new(), } } pub fn with_variable<S: Into<String>>(mut self, variable: S) -> Self { self.variables.push(variable.into()); self } pub fn with_value<E: Into<Expression>>(mut self, value: E) -> Self { self.values.push(value.into()); self } pub fn into_assignments(self) -> (Vec<String>, Vec<Expression>) { (self.variables, self.values) } pub fn append_assignment<S: Into<String>>(&mut self, variable: S, value: Expression) { self.variables.push(variable.into()); self.values.push(value); } pub fn for_each_assignment<F>(&mut self, mut callback: F) where F: FnMut(&mut String, Option<&mut Expression>) { let mut values = self.values.iter_mut(); self.variables.iter_mut() .for_each(|variable| callback(variable, values.next())); } #[inline] pub fn get_variables(&self) -> &Vec<String> { &self.variables } #[inline] pub fn mutate_variables(&mut self) -> &mut Vec<String> { &mut self.variables } #[inline] pub fn get_values(&self) -> &Vec<Expression> { &self.values } #[inline] pub fn mutate_values(&mut self) -> &mut Vec<Expression> { &mut self.values } #[inline] pub fn value_count(&self) -> usize { self.values.len() } #[inline] pub fn variable_count(&self) -> usize { self.variables.len() } }