pub fn add(&mut self, name: &str, value: Value) {
        let exist = self.get(name);

        match exist {
            Some(_) => {
                let index = self.variables.iter().position(|x| x.name == name).unwrap();

                self.variables.remove(index);

                self.add(name, value);
            }
            None => {
                self.variables.push(Variable {
                    name: String::from(name),
                    value: value,
                });
            }
        }
    }
/// Adding a variable to the collection
Adding a variable to the collection
Adding a variable to the collection
pub fn add(&mut self, name: &str, value: Value) {
        let exist = self.get(name);
        match exist {
            Some(_) => {
                let index = self.variables.iter().position(|x| x.name == name).unwrap();
                self.variables.remove(index);
                self.add(name, value);
            }
            None => {
                self.variables.push(Variable {
                    name: String::from(name),
                    value: value,
                });
            }
        }
    }
pub fn add ( & mut self , name : & str , value : Value ) { let exist = self . get ( name ) ; match exist { Some ( _ ) => { let index = self . variables . iter ( ) . position ( | x | x . name == name ) . unwrap ( ) ; self . variables . remove ( index ) ; self . add ( name , value ) ; } None => { self . variables . push ( Variable { name : String :: from ( name ) , value : value , } ) ; } } }
Adding a variable to the collection
Adding a variable to the collection
&mut self
name
&str
value
Value