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 particularpath
. - 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
andrm
is forbidden. - Cross-filesystem locking is broken on Linux before 2.6.12.
Implementations§
Source§impl LockFileGuard
impl LockFileGuard
Sourcepub fn lock<P>(path: P) -> Result<Self, Error>
pub fn lock<P>(path: P) -> Result<Self, Error>
Try to construct a new LockFileGuard
representing a lock we hold on
the file path
.
Blocks until we can get the lock.
Sourcepub fn try_lock<P>(path: P) -> Result<Option<Self>, Error>
pub fn try_lock<P>(path: P) -> Result<Option<Self>, Error>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LockFileGuard
impl RefUnwindSafe for LockFileGuard
impl Send for LockFileGuard
impl Sync for LockFileGuard
impl Unpin for LockFileGuard
impl UnwindSafe for LockFileGuard
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