fd_lock/
read_guard.rs

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