1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::ops::Deref;
use FlockLock;
use InitFlockLock;
use std::fs::File;
use std::io;
#[derive(Debug)]
pub struct SharedSliceLock<'a>(&'a File);
impl<'a> SharedSliceLock<'a> {
pub fn lock(f: &'a File) -> Result<Self, io::Error> {
crate::sys::lock_shared::<Self>(f)
}
pub fn try_lock(f: &'a File) -> Result<Option<Self>, io::Error> {
crate::sys::try_lock_shared::<Self>(f)
}
}
impl<'a> InitFlockLock for SharedSliceLock<'a> {
type Lock = Self;
type Arg = &'a File;
fn new(f: Self::Arg) -> Self::Lock {
SharedSliceLock(f)
}
}
impl<'a> Deref for SharedSliceLock<'a> {
type Target = File;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> FlockLock for SharedSliceLock<'a> {}
impl<'a> Into<&'a File> for SharedSliceLock<'a> {
#[inline(always)]
fn into(self) -> &'a File {
self.0
}
}
impl<'a> AsRef<File> for SharedSliceLock<'a> {
#[inline(always)]
fn as_ref(&self) -> &File {
&*self
}
}
impl<'a> Drop for SharedSliceLock<'a> {
fn drop(&mut self) {
let _e = crate::sys::unlock(&self.0);
}
}