How to update existing data structure with deserialization?

A little bit of background: I'm working on a snippet manager meant to handle multiple libraries. I have a two different implementations of a working deserializer.

I Have a set of toml files that contain snippets, and a map like data structure(radix-trie), that supports deserialization. syntax wise, it behaves enough like a hashmap that I figured out how to deserialize to it by finding questions dealing with hashmaps and serde.

I've confirmed in that deserialization of the current file structure works by deserializing and then reserializing the toml files, with the only difference being the output was alphabetized.

#[derive(Serialize,Deserialize, Clone, Debug)]
    struct SnipTree {
        snippets: radix_trie::Trie<String,Snippet>,
let snippet_data =
            .expect("failed to load file");
    let mut snipTrie: SnipTree = toml::from_str(&snippet_data).unwrap();

    let snip_toml=toml::to_string(&snipTree).unwrap();

I currently have a way to handle the Trie frequently updating by storing each snippet in a separate toml file, and then storing them in a trie after the fact.

pub fn add_from_toml(&mut self, directory: &str, toml_file: &str) {
        let snippet_data =
            fs::read_to_string([directory, &toml_file].join("")).expect("failed to load file");
        let trigger = toml_file
            .expect("could not strip suffix")
                .unwrap_or_else(|err| panic!("Error while reading config [{}]", err)),

however this is less desirable both for performance(not only multiple file reads but snippets may be composed of snippets and without explicit ordering updating the Trie would take multiple passes), and aesthetics(the resulting directories are going to look janky).

If possible I would like to instantiate an empty Trie, and then just update the existing Data Structure with each set of snippets. I'm having trouble finding examples or documentation of this usecase (with a hashmap), and I'm not entirely sure that it is possible, though I don't see why it wouldn't be supported given that deserialization of the file/string remains exactly the same.

How would I go about this?

Okay, so I looked around a bit more and tested it, this is possible with Hashmaps thanks to the extend trait, which isn't currently available for radix_trie.

I opened an issue to see if I could help out with this. The other option is to switch to another implementation, such as qp-trie-rs, or hand-roll my own... which I'd rather avoid because it's pointless to reinvent the wheel if all I need is better tread.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.