4 releases
0.2.0 | Sep 7, 2020 |
---|---|
0.1.3 | May 24, 2020 |
0.1.2 | May 24, 2020 |
0.1.1 | May 24, 2020 |
#975 in Filesystem
11KB
157 lines
Fail-safe file sequence
Implemented in Rust. Inspired by this Java implementation
Usage
let initial_value = 1;
let seq = FileSeq::new(store_dir, initial_value).unwrap();
// Get current value
seq.value().unwrap();
// Increment by 1 and get
seq.increment_and_get(1).unwrap();
// Get, then increment by 1
seq.get_and_increment(1).unwrap();
Changelog
0.2.0 (2020-09-07)
- Ignore errors on
FileSeq::delete
function #1
lib.rs
:
Fail-safe file sequence
Works by versioning values of sequences and throwing away all versions, but the current and the previous one.
Inspired by this Java implementation
Usage
use file_seq::FileSeq;
use std::path::Path;
let dir = Path::new("/tmp/example");
let initial_value = 1;
let seq = FileSeq::new(&dir, initial_value).unwrap();
// Get current value
assert_eq!(initial_value, seq.value().unwrap());
// Increment and get
assert_eq!(initial_value + 1, seq.increment_and_get(1).unwrap());
// Get and then increment
assert_eq!(initial_value + 1, seq.get_and_increment(1).unwrap());
assert_eq!(initial_value + 2, seq.value().unwrap());
Dependencies
~86KB