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 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