pub struct Lock { /* private fields */ }Expand description
An acquired single-instance lock.
The lock is released when this value is dropped (closing the file descriptor releases the OS-level lock). The lock file itself is not deleted on drop — leaving stale lock files on disk after a crash is normal and harmless because the lock is held by the open fd, not by the file’s mere existence.
Implementations§
Source§impl Lock
impl Lock
Sourcepub fn acquire(path: impl AsRef<Path>) -> Result<Self, LockError>
pub fn acquire(path: impl AsRef<Path>) -> Result<Self, LockError>
Acquire the single-instance lock at path.
The function:
- Calls
symlink_metadataand refuses if the path is a symlink (F-2). - Opens the file with
O_NOFOLLOWsemantics (via fresh metadata check then create-or-open). - Calls
try_lock_exclusive. If another process holds the lock, returnsLockError::AlreadyHeld.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lock
impl RefUnwindSafe for Lock
impl Send for Lock
impl Sync for Lock
impl Unpin for Lock
impl UnsafeUnpin for Lock
impl UnwindSafe for Lock
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