DotlockOptions

Struct DotlockOptions 

Source
pub struct DotlockOptions { /* private fields */ }
Expand description

Options which can be used to configure how a lock file is created.

This builder exposes the ability to configure how a lock file is created. The Dotlock::create method is an alias for the create method here.

To use DotlockOptions, first call new, then chain calls to methods to set each option required, and finally call create with the full path of the lock file to create. This will give you a io::Result with a Dotlock inside.

§Examples

Create a lock file using the defaults:

use dotlock::DotlockOptions;

DotlockOptions::new().create("database.lock").unwrap();

Create a lock file, but failing immediately if creating it fails, and remove lock files older than 5 minutes.

use dotlock::DotlockOptions;
use std::time::Duration;

DotlockOptions::new()
    .tries(1)
    .stale_age(Duration::from_secs(300))
    .create("database.lock").unwrap();

Implementations§

Source§

impl DotlockOptions

Source

pub fn new() -> Self

Create a new set of options.

Source

pub fn pause<T: Into<Duration>>(self, pause: T) -> Self

Set the time Dotlock will pause between attempts to create the lock file. Defaults to 5 seconds.

Source

pub fn tries(self, tries: usize) -> Self

Set the number of times Dotlock will try to create the lock file. Defaults to 10 times.

Source

pub fn permissions(self, perm: Permissions) -> Self

Set the permissions on the newly created lock file. If not set, the lock file permissions will be based on the current umask.

Source

pub fn stale_age<T: Into<Duration>>(self, age: T) -> Self

Set the age at which a lock file is considered stale. If not set, the existing file age will not be considered for staleness.

Source

pub fn create<T: Into<PathBuf>>(self, path: T) -> Result<Dotlock>

Create the lock file at path with the options in self.

Trait Implementations§

Source§

impl Debug for DotlockOptions

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.