pub struct LockedFile { /* private fields */ }Expand description
A locked file that provides safe read/write access.
This is a convenience wrapper that combines file locking with read/write operations in a single API.
Implementations§
Source§impl LockedFile
impl LockedFile
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Creates a new locked file handle for the given path.
Sourcepub fn read(&self, path: &Path) -> Result<String>
pub fn read(&self, path: &Path) -> Result<String>
Reads the file contents with a shared lock.
If the file doesn’t exist, returns an empty string.
Sourcepub fn write(&self, path: &Path, content: &str) -> Result<()>
pub fn write(&self, path: &Path, content: &str) -> Result<()>
Writes content to the file with an exclusive lock.
Executes a read operation with a shared lock.
Sourcepub fn with_exclusive_lock<T, F>(&self, f: F) -> Result<T>
pub fn with_exclusive_lock<T, F>(&self, f: F) -> Result<T>
Executes a write operation with an exclusive lock.
Auto Trait Implementations§
impl Freeze for LockedFile
impl RefUnwindSafe for LockedFile
impl Send for LockedFile
impl Sync for LockedFile
impl Unpin for LockedFile
impl UnsafeUnpin for LockedFile
impl UnwindSafe for LockedFile
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