Now I'm worried about the value becoming too large. So possibly I should switch to impl std::io::Read and when the size reaches say 20MB offload to disk.
Once disk is targeted, be sure to retrieve / append in chunks.
How do I do this in Rust? - Happy to use any third-party crate!
EDIT0: I was thinking Apache Arrow + Apache Parquet but maybe that's too much Apache!!
The system is quite good at swapping (and compressing RAM). It makes the decission by usage and not by "oh, but this is bigger than 20 MB".
Implementing your own swapping will not just open an can of worms, but a barrel of them.
If you insist in swapping, use a db (as suggested). They already have put a lot of effort into that subject.
The conclusion we came to in Android is that right now, SQLite is the correct solution for mappings that need to be stored on disk. Yes, it's boring to pick a non-rust implementation, but it is what it is.