parallel_disk_usage/hardlink/
record.rs

1use std::{fs::Metadata, path::Path};
2
3/// Argument to pass to [`RecordHardlinks::record_hardlinks`].
4#[derive(Debug, Clone, Copy)]
5pub struct Argument<'a, Size, Report: ?Sized> {
6    pub path: &'a Path,
7    pub stats: &'a Metadata,
8    pub size: Size,
9    pub reporter: &'a Report,
10}
11
12pub use Argument as RecordHardlinksArgument;
13
14impl<'a, Size, Report: ?Sized> Argument<'a, Size, Report> {
15    #[inline]
16    pub(crate) fn new(
17        path: &'a Path,
18        stats: &'a Metadata,
19        size: Size,
20        reporter: &'a Report,
21    ) -> Self {
22        Argument {
23            path,
24            stats,
25            size,
26            reporter,
27        }
28    }
29}
30
31/// Ability to detect and record hardlinks.
32pub trait RecordHardlinks<Size, Reporter: ?Sized> {
33    /// Error when [`RecordHardlinks::record_hardlinks`] fails.
34    type Error;
35    /// Perform hardlinks detection and recording.
36    fn record_hardlinks(&self, argument: Argument<Size, Reporter>) -> Result<(), Self::Error>;
37}
38
39/// Do detect and record hardlinks.
40#[cfg(unix)]
41pub type Do<Size> = super::HardlinkAware<Size>;
42/// Do not detect nor record hardlinks.
43pub type DoNot = super::HardlinkIgnorant;