Struct LockFileGuard

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

A lock-file for which we hold the lock.

So long as this object exists, we hold the lock on this file. When it is dropped, we will release the lock.

§Semantics

  • Only one LockFileGuard can exist at one time for any particular path.
  • This applies across all tasks and threads in all programs; other acquisitions of the lock in the same process are prevented.
  • This applies across even separate machines, if path is on a shared filesystem.

§Restrictions

  • path must only be deleted (or renamed) via the APIs in this module
  • This restriction applies to all programs on the computer, so for example automatic file cleaning with find and rm is forbidden.
  • Cross-filesystem locking is broken on Linux before 2.6.12.

Implementations§

Source§

impl LockFileGuard

Source

pub fn lock<P>(path: P) -> Result<Self, Error>
where P: AsRef<Path>,

Try to construct a new LockFileGuard representing a lock we hold on the file path.

Blocks until we can get the lock.

Source

pub fn try_lock<P>(path: P) -> Result<Option<Self>, Error>
where P: AsRef<Path>,

Try to construct a new LockFileGuard representing a lock we hold on the file path.

Does not block; returns Ok(None) if somebody else holds the lock.

Source

pub fn delete_lock_file<P>(self, path: P) -> Result<(), Error>
where P: AsRef<Path>,

Try to delete the lock file that we hold.

The provided path must be the same as was passed to lock.

Trait Implementations§

Source§

impl Debug for LockFileGuard

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.