parallel_disk_usage/hardlink/
link_path_list.rs

1mod iter;
2mod reflection;
3
4pub use iter::Iter;
5pub use reflection::Reflection;
6
7pub use Reflection as LinkPathListReflection;
8
9use std::path::PathBuf;
10
11/// List of different hardlinks to the same file.
12///
13/// **Reflection:** `LinkPathList` does not implement `PartialEq`, `Eq`,
14/// `Deserialize`, and `Serialize` directly. Instead, it can be converted into a
15/// [`Reflection`] which implement these traits. Do note that the time complexity
16/// of such conversion is O(n) as it has to convert a `Vec` into a `HashSet`.
17#[derive(Debug, Clone)]
18pub struct LinkPathList(Vec<PathBuf>);
19
20impl LinkPathList {
21    /// Create a list of a single path.
22    #[cfg(any(unix, test))]
23    #[inline]
24    pub(crate) fn single(path: PathBuf) -> Self {
25        LinkPathList(vec![path])
26    }
27
28    /// Create a list of many paths.
29    #[cfg(test)]
30    pub(crate) fn many(paths: impl IntoIterator<Item: Into<PathBuf>>) -> Self {
31        let paths: Vec<_> = paths.into_iter().map(Into::into).collect();
32        assert!(!paths.is_empty(), "paths must not be empty");
33        LinkPathList(paths)
34    }
35
36    /// Add a path to the list.
37    #[cfg(any(unix, test))]
38    #[inline]
39    pub(crate) fn add(&mut self, path: PathBuf) {
40        self.0.push(path)
41    }
42
43    /// Get the number of paths inside the list.
44    #[inline]
45    pub fn len(&self) -> usize {
46        self.0.len()
47    }
48
49    /// Check whether the list is empty.
50    #[inline]
51    pub fn is_empty(&self) -> bool {
52        self.0.is_empty()
53    }
54
55    /// Create reflection.
56    #[inline]
57    pub fn into_reflection(self) -> Reflection {
58        self.into()
59    }
60}
61
62#[cfg(test)]
63mod test;