Struct file_lock::FileLock[][src]

pub struct FileLock {
    pub file: File,
}

Represents the actualy locked file

Fields

the std::fs::File of the file that's locked

Methods

impl FileLock
[src]

Try to lock the specified file

Parameters

filename is the path of the file we want to lock on

is_blocking is a flag to indicate if we should block if it's already locked

is_writable is a flag to indicate if we want to lock for writing

Examples


use file_lock::FileLock;

let filelock = match FileLock::lock("myfile.txt", true, true) {
    Ok(lock) => lock,
    Err(err) => panic!("Error getting a blocked write lock: {}", err),
};

Unlock our locked file

Note: This method is optional as lockfile will be unlocked automatically when dropped

Examples

use file_lock::FileLock;

let filelock = match FileLock::lock("myfile.txt", true, true) {
    Ok(lock) => lock,
    Err(err) => panic!("Error getting a blocked write lock: {}", err),
};

match filelock.unlock() {
    Ok(_)    => println!("Successfully unlocked the file"),
    Err(err) => panic!("Error unlocking the file: {}", err),
};

Trait Implementations

impl Debug for FileLock
[src]

Formats the value using the given formatter. Read more

impl Drop for FileLock
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for FileLock

impl Sync for FileLock