pub trait FdLock: AsRawFd {
// Provided methods
fn flock(&self, operation: Operation) -> Result<()> { ... }
fn lock_shared(&self) -> Result<()> { ... }
fn lock_exclusive(&self) -> Result<()> { ... }
fn try_lock_shared(&self) -> Result<()> { ... }
fn try_lock_exclusive(&self) -> Result<()> { ... }
fn unlock(&self) -> Result<()> { ... }
}
Expand description
The FdLock
trait extends the AsRawFd
trait, allowing
file locks to be placed on file descriptors.
Provided Methods§
Places a shared lock on the file.
This method uses the LOCK_SH
operation to place a shared lock on the associated file descriptor.
§Errors
If the lock operation fails, an io::Error
is returned.
Sourcefn lock_exclusive(&self) -> Result<()>
fn lock_exclusive(&self) -> Result<()>
Places an exclusive lock on the file.
This method uses the LOCK_EX
operation to place an exclusive lock on the associated file descriptor.
§Errors
If the lock operation fails, an io::Error
is returned.
Tries to place a shared lock on the file.
This method uses the LOCK_SH | LOCK_NB
operations to try placing a shared lock on the associated file descriptor.
§Errors
If the lock operation fails or the lock is not immediately available, an io::Error
is returned.
Sourcefn try_lock_exclusive(&self) -> Result<()>
fn try_lock_exclusive(&self) -> Result<()>
Tries to place an exclusive lock on the file.
This method uses the LOCK_EX | LOCK_NB
operations to try placing an exclusive lock on the associated file descriptor.
§Errors
If the lock operation fails or the lock is not immediately available, an io::Error
is returned.