Struct file_lock::FileLock [−][src]
pub struct FileLock { pub file: File, }
Represents the actualy locked file
Fields
file: File
the std::fs::File
of the file that's locked
Methods
impl FileLock
[src]
impl FileLock
pub fn lock(
filename: &str,
is_blocking: bool,
is_writable: bool
) -> Result<FileLock, Error>
[src]
pub fn lock(
filename: &str,
is_blocking: bool,
is_writable: bool
) -> Result<FileLock, Error>
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), };
pub fn unlock(&self) -> Result<(), Error>
[src]
pub fn unlock(&self) -> Result<(), Error>
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]
impl Debug for FileLock
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Drop for FileLock
[src]
impl Drop for FileLock