Trait FdLock

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

Source

fn flock(&self, operation: Operation) -> Result<()>

Places a file lock on the associated file descriptor using the flock operation.

§Arguments
  • operation: The type of lock to place on the file.
§Errors

If the lock operation fails, an io::Error is returned.

Source

fn lock_shared(&self) -> Result<()>

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.

Source

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.

Source

fn try_lock_shared(&self) -> Result<()>

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.

Source

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.

Source

fn unlock(&self) -> Result<()>

Unlocks the file.

This method removes the lock held by the current process on the associated file descriptor. It uses the LOCK_UN operation to unlock the file.

§Errors

If the unlock operation fails, an io::Error is returned.

Implementations on Foreign Types§

Source§

impl FdLock for File

Implementors§