Skip to main content

cc_audit/error/
context.rs

1//! Error context types for better error messages.
2
3/// I/O operation types.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum IoOperation {
6    Read,
7    Write,
8    Create,
9    Delete,
10    SetPermissions,
11}
12
13impl std::fmt::Display for IoOperation {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Self::Read => write!(f, "read"),
17            Self::Write => write!(f, "write"),
18            Self::Create => write!(f, "create"),
19            Self::Delete => write!(f, "delete"),
20            Self::SetPermissions => write!(f, "set permissions"),
21        }
22    }
23}
24
25/// Parse format types.
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum ParseFormat {
28    Json,
29    Yaml,
30    Toml,
31    Frontmatter,
32}
33
34impl std::fmt::Display for ParseFormat {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            Self::Json => write!(f, "JSON"),
38            Self::Yaml => write!(f, "YAML"),
39            Self::Toml => write!(f, "TOML"),
40            Self::Frontmatter => write!(f, "frontmatter"),
41        }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_io_operation_display() {
51        assert_eq!(IoOperation::Read.to_string(), "read");
52        assert_eq!(IoOperation::Write.to_string(), "write");
53    }
54
55    #[test]
56    fn test_parse_format_display() {
57        assert_eq!(ParseFormat::Json.to_string(), "JSON");
58        assert_eq!(ParseFormat::Yaml.to_string(), "YAML");
59    }
60}