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
/// Operation that caused the error
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Operation {
    /// Error is caused by calling [`std::fs::symlink_metadata`].
    SymlinkMetadata,
    /// Error is caused by calling [`std::fs::read_dir`].
    ReadDirectory,
    /// Error when trying to access [`std::fs::DirEntry`] of one of the element of [`std::fs::read_dir`].
    AccessEntry,
}

impl Operation {
    /// Get name of the operation.
    pub const fn name(self) -> &'static str {
        use Operation::*;
        match self {
            SymlinkMetadata => "symlink_metadata",
            ReadDirectory => "read_dir",
            AccessEntry => "access entry",
        }
    }
}

#[cfg(test)]
mod test_operation {
    use super::*;

    macro_rules! name_display {
        ($name:ident, $variant:ident, $text:literal) => {
            #[test]
            fn $name() {
                assert_eq!(Operation::$variant.name(), $text);
            }
        };
    }

    name_display!(symlink_metadata, SymlinkMetadata, "symlink_metadata");
    name_display!(read_directory, ReadDirectory, "read_dir");
    name_display!(access_entry, AccessEntry, "access entry");
}