Deleting an entry from BTreeMap<String, ..>


I’m using serde_json which converts json to BTreeMap. I would like to delete some unnecessary keys from it and convert it back to json string.

        let mut tree = message.as_object().unwrap();
        let mut del_keys = vec!["__BOOL"];
        for key in del_keys.iter(){


error: the trait `core::borrow::Borrow<&str>` is not implemented for the type `collections::string::String` [E0277]
src/             tree.remove(key);

PS: I’m not sure if I can ask very basic questions like this here.


The code you’ve given and the error don’t match.


Sorry. Please Ignore this question. I just need to do this

let mut tree = message.as_object_mut().unwrap();
        let mut del_keys = vec!["__BOOL", "__CURSOR", "_BOOT_ID"];

        for (key, value) in tree.iter(){
            println!("{:?}", key);
        for key in del_keys.iter(){
            tree.remove(&mut key.to_string());