fd_lock/
write_guard.rs

1use std::ops;
2
3use crate::sys;
4
5/// RAII structure used to release the exclusive write access of a lock when
6/// dropped.
7///
8/// This structure is created by the [`write`] and [`try_write`] methods
9/// on [`RwLock`].
10///
11/// [`write`]: crate::RwLock::write
12/// [`try_write`]: crate::RwLock::try_write
13/// [`RwLock`]: crate::RwLock
14#[must_use = "if unused the RwLock will immediately unlock"]
15#[derive(Debug)]
16pub struct RwLockWriteGuard<'lock, T: sys::AsOpenFile> {
17    guard: sys::RwLockWriteGuard<'lock, T>,
18}
19
20impl<'lock, T: sys::AsOpenFile> RwLockWriteGuard<'lock, T> {
21    pub(crate) fn new(guard: sys::RwLockWriteGuard<'lock, T>) -> Self {
22        Self { guard }
23    }
24}
25
26impl<T: sys::AsOpenFile> ops::Deref for RwLockWriteGuard<'_, T> {
27    type Target = T;
28
29    #[inline]
30    fn deref(&self) -> &Self::Target {
31        self.guard.deref()
32    }
33}
34
35impl<T: sys::AsOpenFile> ops::DerefMut for RwLockWriteGuard<'_, T> {
36    #[inline]
37    fn deref_mut(&mut self) -> &mut Self::Target {
38        self.guard.deref_mut()
39    }
40}
41
42/// Release the lock.
43impl<T: sys::AsOpenFile> Drop for RwLockWriteGuard<'_, T> {
44    #[inline]
45    fn drop(&mut self) {}
46}