pub struct Lock { /* private fields */ }Expand description
Implementations§
Source§impl Lock
impl Lock
Sourcepub fn new(name: &str) -> Result<Self>
pub fn new(name: &str) -> Result<Self>
Open (or create) a named lock identified by name.
§Platform behaviour
- Unix — creates/opens
$TMPDIR/<name>.lock(falls back to/tmp/<name>.lockwhenTMPDIRis unset). - Windows — creates/opens a kernel mutex named
Global\<name>.
§Errors
Returns Error::InvalidName for illegal names, or Error::Io if
the OS operation fails.
Sourcepub fn path(&self) -> &Path
Available on Unix only.
pub fn path(&self) -> &Path
Return the filesystem path of the backing lock file (Unix only).
This is the path used by Lock::new or Lock::with_path. It can be
used by callers to clean up the lock file when they know it is safe to do
so. The library itself intentionally leaves the file in place; deleting it
while another process may still be using the lock can break mutual
exclusion.
Sourcepub fn try_lock(&self) -> Result<LockGuard>
pub fn try_lock(&self) -> Result<LockGuard>
Try to acquire the lock without blocking.
Returns a LockGuard if the lock is free, or
Error::WouldBlock if it is currently held.
§Errors
Returns Error::WouldBlock when the lock is held, or Error::Io
for any other OS-level failure.
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