]> git.proxmox.com Git - rustc.git/blame - vendor/fd-lock/src/write_guard.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / vendor / fd-lock / src / write_guard.rs
CommitLineData
064997fb
FG
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
064997fb
FG
14#[must_use = "if unused the RwLock will immediately unlock"]
15#[derive(Debug)]
16pub struct RwLockWriteGuard<'lock, T: sys::AsRaw> {
17 guard: sys::RwLockWriteGuard<'lock, T>,
18}
19
20impl<'lock, T: sys::AsRaw> RwLockWriteGuard<'lock, T> {
21 pub(crate) fn new(guard: sys::RwLockWriteGuard<'lock, T>) -> Self {
22 Self { guard }
23 }
24}
25
26impl<T: sys::AsRaw> 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::AsRaw> 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::AsRaw> Drop for RwLockWriteGuard<'_, T> {
44 #[inline]
45 fn drop(&mut self) {}
46}