files/
files.rs

1fn main() {
2    // Our Data:
3    let data = vec![
4        (1, "Hello".as_bytes().to_vec()),
5        (2, ", ".as_bytes().to_vec()),
6        (4, "world".as_bytes().to_vec()),
7        (1, "!".as_bytes().to_vec()),
8    ];
9
10    // Write to file.
11    // Note that one should not panic!() in real life.
12    match kvds::encode_to_file("data", data) {
13        Err(e) => panic!("Err: {:?}", e),
14        _ => (),
15    }
16
17    // Read from file.
18    let decoded_data = match kvds::decode_from_file("data") {
19        Ok(d) => d,
20        Err(e) => panic!("Err: {:?}", e), // Again, DO NOT PANIC!() IRL.
21    };
22
23    // Print it.  It should look like a Vec<(u8, Vec<u8>)>, same as the original `data`!
24    println!("{:?}", decoded_data);
25}