pub struct NamedLock { /* private fields */ }
Expand description
Cross-process lock that is identified by name.
Implementations§
Source§impl NamedLock
impl NamedLock
Sourcepub fn create(name: &str) -> Result<NamedLock>
pub fn create(name: &str) -> Result<NamedLock>
Create/open a named lock.
§UNIX
This will create/open a file and use flock
on it. The path of
the lock file will be $TMPDIR/<name>.lock
, or /tmp/<name>.lock
if TMPDIR
environment variable is not set.
If you want to specify the exact path, then use NamedLock::with_path.
§Windows
This will create/open a global mutex with CreateMutexW
.
§Notes
name
must not be empty, otherwise an error is returned.name
must not contain\0
,/
, nor\
, otherwise an error is returned.
Sourcepub fn with_path<P>(path: P) -> Result<NamedLock>
Available on Unix only.
pub fn with_path<P>(path: P) -> Result<NamedLock>
Create/open a named lock on specified path.
§Notes
- This function does not append
.lock
on the path. - Parent directories must exist.
Sourcepub fn try_lock(&self) -> Result<NamedLockGuard>
pub fn try_lock(&self) -> Result<NamedLockGuard>
Try to lock named lock.
If it is already locked, Error::WouldBlock
will be returned.
Sourcepub fn lock(&self) -> Result<NamedLockGuard>
pub fn lock(&self) -> Result<NamedLockGuard>
Lock named lock.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NamedLock
impl !RefUnwindSafe for NamedLock
impl Send for NamedLock
impl Sync for NamedLock
impl Unpin for NamedLock
impl !UnwindSafe for NamedLock
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