pub fn merge_json(&mut self, json: &Value) -> Result<usize, Error> {
        if let Value::Object(map) = json {
            // Turns the map into a [SettingInfo] to insert: we only insert
            // setttings that are new.
            let settings: Vec<SettingInfo> = map
                .iter()
                .filter_map(|(name, value)| {
                    if self.get(name).is_err() {
                        Some(SettingInfo {
                            name: name.clone(),
                            value: JsonValue::from((*value).clone()),
                        })
                    } else {
                        None
                    }
                })
                .collect();
            self.set(&settings)?;
            Ok(settings.len())
        } else {
            Err(Error::InvalidImport)
        }
    }
// Import all the new value pairs from the json object.
// Returns the number of inserted settings.
Import all the new value pairs from the json object.
Returns the number of inserted settings.
Import all the new value pairs from the json object . Returns the number of inserted settings .
pub fn merge_json(&mut self, json: &Value) -> Result<usize, Error> {
        if let Value::Object(map) = json {
            // Turns the map into a [SettingInfo] to insert: we only insert
            // setttings that are new.
            let settings: Vec<SettingInfo> = map
                .iter()
                .filter_map(|(name, value)| {
                    if self.get(name).is_err() {
                        Some(SettingInfo {
                            name: name.clone(),
                            value: JsonValue::from((*value).clone()),
                        })
                    } else {
                        None
                    }
                })
                .collect();
            self.set(&settings)?;
            Ok(settings.len())
        } else {
            Err(Error::InvalidImport)
        }
    }
pub fn merge_json ( & mut self , json : & Value ) -> Result < usize , Error > { if let Value :: Object ( map ) = json { // Turns the map into a [SettingInfo] to insert: we only insert // setttings that are new. let settings : Vec < SettingInfo > = map . iter ( ) . filter_map ( | ( name , value ) | { if self . get ( name ) . is_err ( ) { Some ( SettingInfo { name : name . clone ( ) , value : JsonValue :: from ( ( * value ) . clone ( ) ) , } ) } else { None } } ) . collect ( ) ; self . set ( & settings ) ? ; Ok ( settings . len ( ) ) } else { Err ( Error :: InvalidImport ) } }
Import all the new value pairs from the json object.
Import all the new value pairs from the json object .
&mut self
json
&Value
&mut self
json
&Value