Skip to main content

edikt_core/
feature.rs

1//! Format capabilities.
2//!
3//! Each format module declares a static `&[Feature]`. The set is consulted at
4//! edit time (an operation needing a feature the format lacks fails cleanly) and
5//! at conversion time (each source-used feature the target lacks is a warning).
6
7/// A capability a config format may or may not support.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub enum Feature {
10    /// Comments / trivia the CST preserves (JSONC, INI, `.env` - not plain JSON).
11    Comments,
12    /// Nested containers beyond a single level (JSON objects/arrays).
13    Nesting,
14    /// Ordered sequences.
15    Arrays,
16    /// Non-string scalars: numbers, booleans, null.
17    TypedScalars,
18    /// A single level of named grouping (INI `[section]`).
19    Sections,
20}
21
22impl Feature {
23    /// Human-readable name, used in conversion warnings.
24    pub fn as_str(self) -> &'static str {
25        match self {
26            Feature::Comments => "comments",
27            Feature::Nesting => "nesting",
28            Feature::Arrays => "arrays",
29            Feature::TypedScalars => "typed scalars",
30            Feature::Sections => "sections",
31        }
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn names() {
41        assert_eq!(Feature::Comments.as_str(), "comments");
42        assert_eq!(Feature::Nesting.as_str(), "nesting");
43        assert_eq!(Feature::Arrays.as_str(), "arrays");
44        assert_eq!(Feature::TypedScalars.as_str(), "typed scalars");
45        assert_eq!(Feature::Sections.as_str(), "sections");
46    }
47}