Writing/Reading a HashMap to/from a file

Is there any way to write a HashMap to a file so that it can be stored and then read at a later time?

I'm guessing if it is possible, I would somehow have to use serde...

Yes, Serde is the right tool for this. If you want to write as JSON, you can open a file for writing and call:

serde_json::to_writer(file, hashmap)?;

There are other formats, such as https://lib.rs/bincode


Works, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.