Struct named_lock::NamedLock
source · [−]pub struct NamedLock { /* private fields */ }Expand description
Cross-process lock that is identified by name.
Implementations
sourceimpl 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
namemust not be empty, otherwise an error is returned.namemust not contain\0,/, nor\, otherwise an error is returned.
sourcepub fn with_path<P>(path: P) -> Result<NamedLock>where
P: AsRef<Path>,
Available on Unix only.
pub fn with_path<P>(path: P) -> Result<NamedLock>where
P: AsRef<Path>,
Create/open a named lock on specified path.
Notes
- This function does not append
.lockon 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 !RefUnwindSafe for NamedLock
impl Send for NamedLock
impl Sync for NamedLock
impl Unpin for NamedLock
impl !UnwindSafe for NamedLock
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more