pub enum LockType {
Shared,
Exclusive,
}Expand description
Type of file lock.
Used with FsLock::lock to request either shared
or exclusive access to a file.
§Variants
| Variant | Behavior |
|---|---|
Shared | Multiple readers allowed simultaneously |
Exclusive | Single writer, no other access |
§Lock Compatibility
| Held Lock | Shared Request | Exclusive Request |
|---|---|---|
| None | ✓ Granted | ✓ Granted |
| Shared | ✓ Granted | ✗ Blocked |
| Exclusive | ✗ Blocked | ✗ Blocked |
§Example
use anyfs_backend::{FsLock, FsHandles, OpenFlags, LockType};
use std::path::Path;
// Generic function that works with any FsHandles + FsLock implementation
fn safe_read<B: FsHandles + FsLock>(fs: &B) -> Result<(), anyfs_backend::FsError> {
let handle = fs.open(Path::new("/data.txt"), OpenFlags::READ)?;
// Shared lock allows concurrent readers
fs.lock(handle, LockType::Shared)?;
// ... read data ...
fs.unlock(handle)?;
fs.close(handle)?;
Ok(())
}Variants§
Shared lock — multiple readers allowed simultaneously.
Use when reading data that shouldn’t change during the read. Multiple processes can hold shared locks on the same file.
Exclusive
Exclusive lock — single writer, blocks all other access.
Use when modifying data. Only one process can hold an exclusive lock, and it blocks all shared lock requests.
Trait Implementations§
impl Copy for LockType
impl Eq for LockType
impl StructuralPartialEq for LockType
Auto Trait Implementations§
impl Freeze for LockType
impl RefUnwindSafe for LockType
impl Send for LockType
impl Sync for LockType
impl Unpin for LockType
impl UnwindSafe for LockType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more