-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathiter.rs
More file actions
62 lines (53 loc) · 1.59 KB
/
iter.rs
File metadata and controls
62 lines (53 loc) · 1.59 KB
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
62
use super::{HardlinkList, InodeKey, Value};
use crate::{device::DeviceNumber, hardlink::LinkPathList, inode::InodeNumber};
use dashmap::{iter::Iter as DashIter, mapref::multiple::RefMulti};
use pipe_trait::Pipe;
/// Iterator over entries in [`HardlinkList`].
#[derive(derive_more::Debug)]
#[debug(bound())]
#[debug("Iter(..)")]
pub struct Iter<'a, Size>(DashIter<'a, InodeKey, Value<Size>>);
impl<Size> HardlinkList<Size> {
/// Iterate over the recorded entries.
pub fn iter(&self) -> Iter<'_, Size> {
self.0.iter().pipe(Iter)
}
}
/// [Item](Iterator::Item) of [`Iter`].
#[derive(derive_more::Debug)]
#[debug(bound())]
#[debug("Item(..)")]
pub struct Item<'a, Size>(RefMulti<'a, InodeKey, Value<Size>>);
impl<'a, Size> Iterator for Iter<'a, Size> {
type Item = Item<'a, Size>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(Item)
}
}
impl<'a, Size> Item<'a, Size> {
/// The inode number of the file.
#[inline]
pub fn ino(&self) -> InodeNumber {
self.0.key().ino
}
/// The device number of the filesystem the inode belongs to.
#[inline]
pub fn dev(&self) -> DeviceNumber {
self.0.key().dev
}
/// Size of the file.
#[inline]
pub fn size(&self) -> &Size {
&self.0.value().size
}
/// Total number of links of the file, both listed (in [`Self::paths`]) and unlisted.
#[inline]
pub fn links(&self) -> u64 {
self.0.value().links
}
/// Paths to the detected links of the file.
#[inline]
pub fn paths(&self) -> &LinkPathList {
&self.0.value().paths
}
}