[−][src]Struct file_locker::FileLock
Represents the actually locked file
Fields
file: Filethe std::fs::File of the file that's locked
Implementations
impl FileLock[src]
pub fn new<T: AsRef<Path>>(file_path: T) -> FileLockBuilder<T>[src]
Create a FileLockBuilder
blocking and writeable default to false
Examples
use file_locker::FileLock; use std::io::prelude::*; use std::io::Result; fn main() -> Result<()> { let mut filelock = FileLock::new("myfile.txt") .writeable(true) .blocking(true) .lock()?; filelock.file.write_all(b"Hello, world")?; Ok(()) }
pub fn lock(
file_path: impl AsRef<Path>,
blocking: bool,
writeable: bool
) -> Result<FileLock>[src]
file_path: impl AsRef<Path>,
blocking: bool,
writeable: bool
) -> Result<FileLock>
Try to lock the specified file
Parameters
-
filenameis the path of the file we want to lock on -
is_blockingis a flag to indicate if we should block if it's already locked
If set, this call will block until the lock can be obtained.
If not set, this call will return immediately, giving an error if it would block
is_writableis a flag to indicate if we want to lock for writing
Examples
use file_locker::FileLock; use std::io::prelude::*; use std::io::Result; fn main() -> Result<()> { let mut filelock = FileLock::lock("myfile.txt", false, false)?; let mut buf = String::new(); filelock.file.read_to_string(&mut buf)?; Ok(()) }
pub fn unlock(&self) -> Result<()>[src]
Unlock our locked file
Note: This method is optional as the file lock will be unlocked automatically when dropped
Examples
use file_locker::FileLock; use std::io::prelude::*; use std::io::Result; fn main() -> Result<()> { let mut filelock = FileLock::new("myfile.txt") .writeable(true) .blocking(true) .lock()?; filelock.file.write_all(b"Hello, world")?; filelock.unlock()?; Ok(()) }
Trait Implementations
impl AsRawFd for FileLock[src]
impl Debug for FileLock[src]
impl Drop for FileLock[src]
impl FileExt for FileLock[src]
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>[src]
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>[src]
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<(), Error>1.33.0[src]
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<(), Error>1.33.0[src]
impl Read for FileLock[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize>[src]
fn is_read_vectored(&self) -> bool[src]
unsafe fn initializer(&self) -> Initializer[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>1.6.0[src]
fn by_ref(&mut self) -> &mut Self1.0.0[src]
fn bytes(self) -> Bytes<Self>1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read, 1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>1.0.0[src]
impl Seek for FileLock[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>[src]
fn stream_len(&mut self) -> Result<u64, Error>[src]
fn stream_position(&mut self) -> Result<u64, Error>[src]
impl Write for FileLock[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>[src]
fn flush(&mut self) -> Result<()>[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize>[src]
fn is_write_vectored(&self) -> bool[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src]
fn write_all_vectored(&mut self, bufs: &mut [IoSlice]) -> Result<(), Error>[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src]
fn by_ref(&mut self) -> &mut Self1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for FileLock
impl Send for FileLock
impl Sync for FileLock
impl Unpin for FileLock
impl UnwindSafe for FileLock
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,