SwapVec
A vector which swaps to disk when exceeding a certain length.
Useful when creation and consumption of data should be separated by time, but not much memory should be consumed.
Features
- Multiplatform (Linux, Windows, MacOS)
- Creates temporary file only after exceeding threshold
- Works on
T: Serialize + Deserialize - Temporary file removed even when terminating the program
- Checksums to guarantee integrity
Limitations
- Due to potentially doing IO, most actions are wrapped in a
Result - Currently, no "start swapping after n MiB" is implemented
- Would need element wise space calculation due to heap elements (e.g.
String)
- Would need element wise space calculation due to heap elements (e.g.
Compressioncurrently does not compress. It is there to keep the API stable.- No async support yet
Examples
Basic Usage
use SwapVec;
let iterator = .into_iter;
let mut much_data = default;
// Starts using disk for big iterators
much_data.consume.unwrap;
for value in much_data.into_iter
Extended Usage
This is the code for cargo run (src/main.rs).
use ;
const DATA_MB: u64 = 1024;