Skip to main content

inspect_format/
role.rs

1//! Semantic style roles for inspected elements.
2
3/// Semantic role of an inspected element within output formatting.
4///
5/// Instead of hard-coding raw colors or escape codes in renderers, renderers
6/// request styles by semantic role. Themes map these roles to concrete terminal
7/// styles.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub enum StyleRole {
10    /// Type names (e.g. `Server`, `User`, `Vec<i32>`).
11    Type,
12
13    /// Field or property names in structs/records (e.g. `host`, `port`).
14    Field,
15
16    /// Enum variant names (e.g. `Running`, `Some`, `Ok`).
17    Variant,
18
19    /// Map keys or dictionary entries (e.g. `"host"`, `"port"`).
20    Key,
21
22    /// String literal values (e.g. `"127.0.0.1"`).
23    String,
24
25    /// Numeric values (e.g. `42`, `3.14`, `-12`, `0xff`).
26    Number,
27
28    /// Boolean values (`true`, `false`).
29    Boolean,
30
31    /// Unit or null-like values (`()`, `None`).
32    Null,
33
34    /// Structural punctuation (e.g. `:`, `""`, `[]`, `()`, `::`).
35    Punctuation,
36
37    /// Collection element indices (e.g. `[0]`, `[1]`).
38    Index,
39
40    /// Metadata annotations (e.g. `[16 bytes]`, length indicators).
41    Metadata,
42
43    /// Sensitive or redacted values (e.g. `[REDACTED]`).
44    Sensitive,
45
46    /// Truncation notices (e.g. `… 997 more`, `<truncated>`).
47    Truncated,
48
49    /// Error messages or error variants (e.g. `Err`, `<cycle>`).
50    Error,
51
52    /// Subdued or muted secondary text.
53    Muted,
54}
55
56impl StyleRole {
57    /// Total number of semantic roles.
58    pub const COUNT: usize = 15;
59
60    /// Return an array of all semantic roles.
61    pub const ALL: [Self; Self::COUNT] = [
62        Self::Type,
63        Self::Field,
64        Self::Variant,
65        Self::Key,
66        Self::String,
67        Self::Number,
68        Self::Boolean,
69        Self::Null,
70        Self::Punctuation,
71        Self::Index,
72        Self::Metadata,
73        Self::Sensitive,
74        Self::Truncated,
75        Self::Error,
76        Self::Muted,
77    ];
78
79    /// Returns the integer index corresponding to this role (0 to 14).
80    #[inline]
81    pub const fn index(self) -> usize {
82        self as usize
83    }
84}