Crates.io | wal-rs |
lib.rs | wal-rs |
version | 1.0.2 |
source | src |
created_at | 2018-09-30 07:37:54.351267 |
updated_at | 2018-09-30 07:59:37.236852 |
description | Write-ahead-log implementation |
homepage | https://github.com/dtynn/wal-rs |
repository | https://github.com/dtynn/wal-rs |
max_upload_size | |
id | 87242 |
size | 29,371 |
This is an write-ahead-log implementation.
[dependencies]
wal-rs = "1"
extern crate wal_rs;
extern crate rand;
extern crate wal_rs;
use rand::{thread_rng, Rng};
use std::fs;
use wal_rs::*;
fn main() {
let cfg = Config {
entry_per_segment: 100,
check_crc32: false,
};
let mut wal = WAL::open("./testdir", cfg).unwrap();
let entry_num: usize = 1024;
let mut buf = vec![0; entry_num];
thread_rng().fill(&mut buf[..]);
for i in 0..buf.len() {
wal.write(&buf[..i + 1]).unwrap();
}
assert_eq!(wal.len(), entry_num);
let data = wal.read(entry_num * 2).unwrap();
assert_eq!(data.len(), entry_num);
assert_eq!(wal.len(), 0);
for (i, v) in data.iter().enumerate() {
assert_eq!((i + 1) as usize, v.len());
assert_eq!(&buf[..(i + 1) as usize].to_vec(), v);
}
fs::remove_dir_all("./testdir").unwrap();
}