pub struct FileSeq { /* private fields */ }
Implementations§
Source§impl FileSeq
impl FileSeq
pub fn new<P: AsRef<Path>>(store_dir: P, initial_value: u64) -> Result<Self>
Sourcepub fn delete(&self)
pub fn delete(&self)
Deletes this sequence
Once deleted, the sequence must be recreated
§Example
use file_seq::FileSeq;
use std::path::Path;
let dir = Path::new("/tmp/example_delete");
let initial_value = 1;
let seq = FileSeq::new(&dir, initial_value).unwrap();
// Get current value
assert_eq!(initial_value, seq.value().unwrap());
seq.delete();
// Attempts to read the sequence after it's deleted returns an error
assert_eq!(seq.value().is_err(), true)
Sourcepub fn get_and_increment(&self, increment: u64) -> Result<u64>
pub fn get_and_increment(&self, increment: u64) -> Result<u64>
Returns the current value of the sequence and then increments it.
§Example
use file_seq::FileSeq;
use std::path::Path;
let dir = Path::new("/tmp/example_get_and_increment");
let initial_value = 1;
let seq = FileSeq::new(&dir, initial_value).unwrap();
assert_eq!(initial_value, seq.get_and_increment(1).unwrap());
assert_eq!(initial_value + 1, seq.value().unwrap());
Sourcepub fn increment_and_get(&self, increment: u64) -> Result<u64>
pub fn increment_and_get(&self, increment: u64) -> Result<u64>
Increments the sequence and return the value.
§Example
use file_seq::FileSeq;
use std::path::Path;
let dir = Path::new("/tmp/example_increment_and_get");
let initial_value = 1;
let seq = FileSeq::new(&dir, initial_value).unwrap();
assert_eq!(initial_value + 1, seq.increment_and_get(1).unwrap());
assert_eq!(initial_value + 1, seq.value().unwrap());
Sourcepub fn value(&self) -> Result<u64>
pub fn value(&self) -> Result<u64>
Returns the current value of the sequence.
§Example
use file_seq::FileSeq;
use std::path::Path;
let dir = Path::new("/tmp/example_value");
let initial_value = 1;
let seq = FileSeq::new(&dir, initial_value).unwrap();
assert_eq!(initial_value, seq.value().unwrap());
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileSeq
impl RefUnwindSafe for FileSeq
impl Send for FileSeq
impl Sync for FileSeq
impl Unpin for FileSeq
impl UnwindSafe for FileSeq
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more