proclock_api/
lock_guard.rs

1use fs2::FileExt;
2use std::fs::File;
3
4/// This struct releases the lock on `Drop`, similar to [`MutexGuard`](std::sync::MutexGuard`)'s behaviour
5#[derive(Debug)]
6pub struct LockGuard {
7    /// The file on which the lock has been performed
8    inner: File,
9}
10
11impl From<File> for LockGuard {
12    fn from(inner: File) -> Self {
13        LockGuard { inner }
14    }
15}
16
17impl Drop for LockGuard {
18    fn drop(&mut self) {
19        let _unlock_result = self.inner.unlock();
20    }
21}