Skip to main content

remove_config_section_field

Function remove_config_section_field 

Source
pub fn remove_config_section_field(
    config_json: &str,
    section_name: &str,
    field_name: &str,
) -> Result<(String, usize)>
Expand description

Remove a field from all items in a configuration section

§Arguments

  • config_json - Configuration JSON string
  • section_name - Section name
  • field_name - Field name to remove

§Returns

Returns (modified_config, item_count) tuple on success

§Example

use sz_configtool_lib::config_sections;

let config = r#"{"G2_CONFIG": {"CFG_ATTR": [{"ATTR_CODE": "NAME", "OLD_FIELD": "value"}]}}"#;
let (modified, count) = config_sections::remove_config_section_field(
    config,
    "CFG_ATTR",
    "OLD_FIELD"
).unwrap();
assert_eq!(count, 1);