Struct file_guard::FileGuard

source ·
pub struct FileGuard<T: Deref<Target = File>> { /* private fields */ }
Expand description

An RAII implementation of a “scoped lock” of a file. When this structure is dropped (falls out of scope), the lock will be unlocked.

This structure is created by the lock(), try_lock(), and lock_any() functions.

Implementations§

source§

impl<T> FileGuard<T>
where T: Deref<Target = File>,

source

pub fn lock_type(&self) -> Lock

Gets the Lock type currently held.

source

pub fn is_shared(&self) -> bool

Test if the currently held Lock type is Shared.

source

pub fn is_exclusive(&self) -> bool

Test if the currently held Lock type is Exclusive.

source

pub fn range(&self) -> Range<usize>

Gets the byte range of the held lock.

source

pub fn offset(&self) -> usize

Gets the byte offset of the held lock.

source

pub fn len(&self) -> usize

Gets the byte length of the held lock.

source

pub fn is_empty(&self) -> bool

Tests if the byte range of the lock has a length of zero.

source

pub fn downgrade(&mut self) -> Result<()>

Safely exchanges an Exclusive Lock for a Shared one.

If the currently held lock is already Shared, no change is made and the method succeeds. This exchange safely ensures no lock is released during operation. That is, no waiting Exclusive lock attempts may obtain the lock during the downgrade. Other Shared locks waiting will be granted a lock as a result, however.

Trait Implementations§

source§

impl<T> Debug for FileGuard<T>
where T: Deref<Target = File>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for FileGuard<T>
where T: Deref<Target = File>,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T> DerefMut for FileGuard<T>
where T: DerefMut<Target = File>,

source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
source§

impl<T> Drop for FileGuard<T>
where T: Deref<Target = File>,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> FileGuardExt for FileGuard<T>
where T: Deref<Target = File>,

source§

fn upgrade(&mut self) -> Result<()>

Upgrades a lock from Shared to Exclusive. Read more
source§

fn try_upgrade(&mut self) -> Result<()>

Attempts to upgrade a lock from Shared to Exclusive. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FileGuard<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for FileGuard<T>
where T: RefUnwindSafe,

§

impl<T> Send for FileGuard<T>
where T: Send,

§

impl<T> Sync for FileGuard<T>
where T: Sync,

§

impl<T> Unpin for FileGuard<T>
where T: Unpin,

§

impl<T> UnwindSafe for FileGuard<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.