Crates.io | indexed_storage |
lib.rs | indexed_storage |
version | 0.1.1 |
source | src |
created_at | 2021-06-11 19:15:54.194635 |
updated_at | 2021-06-14 18:57:55.497803 |
description | Fast and lightweight indexed binary storage |
homepage | |
repository | |
max_upload_size | |
id | 409096 |
size | 6,267 |
Fast and lightweight indexed binary data storage
[dependencies]
indexed_storage = "0.1.0"
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Entity {
x: f32,
y: f32,
}
fn main() {
let mut writer = indexed_storage::new_writer("db");
for i in 0..100000 {
let entry = Entity {
x: i as f32,
y: (i as f32).sqrt(),
};
let encoded: Vec<u8> = bincode::serialize(&entry).unwrap();
writer.write_all(&encoded).expect("could not write to db");
}
let mut reader = indexed_storage::new_reader("db");
let encoded = reader.read(8).expect("could not read from db");
let entry: Entity = bincode::deserialize(&encoded).unwrap();
// will print:
// Entity { x: 8.0, y: 2.828427 }
println!("{:?}", entry);
}