file_seq

Struct FileSeq

Source
pub struct FileSeq { /* private fields */ }

Implementations§

Source§

impl FileSeq

Source

pub fn new<P: AsRef<Path>>(store_dir: P, initial_value: u64) -> Result<Self>

Source

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)
Source

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());
Source

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());
Source

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§

Source§

impl Debug for FileSeq

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.