Skip to main content

declint_core/
presets.rs

1//! The embedded preset library: curated config fragments shipped with
2//! declint, imported as `import: preset:<name>`.
3//!
4//! The presets are ordinary YAML config files living in this crate's
5//! `presets/` directory (so they ship inside the published package) and
6//! embedded at compile time — binaries are self-contained, and CI needs
7//! nothing beyond the executable.
8
9/// One embedded preset.
10pub struct Preset {
11    /// The name used in `import: preset:<name>`.
12    pub name: &'static str,
13    /// One-line summary shown by `declint presets`.
14    pub description: &'static str,
15    /// The full YAML content.
16    pub content: &'static str,
17}
18
19/// Every embedded preset, in display order.
20pub static PRESETS: &[Preset] = &[
21    Preset {
22        name: "python",
23        description: "Python: PEP 8 warm-ups, == None, mutable defaults, \
24                      top-level function/class scopes",
25        content: include_str!("../presets/python.yaml"),
26    },
27    Preset {
28        name: "ini",
29        description: "INI: tabs, trailing whitespace, empty values, \
30                      a [server] section example",
31        content: include_str!("../presets/ini.yaml"),
32    },
33    Preset {
34        name: "markdown",
35        description: "Markdown: tabs, trailing whitespace, bare URLs",
36        content: include_str!("../presets/markdown.yaml"),
37    },
38];
39
40/// Looks up an embedded preset by name.
41pub fn lookup(name: &str) -> Option<&'static Preset> {
42    PRESETS.iter().find(|preset| preset.name == name)
43}
44
45/// The names of every embedded preset, comma-separated — for error
46/// messages ("unknown preset `x` (available: python, ini, markdown)").
47pub fn names() -> String {
48    PRESETS
49        .iter()
50        .map(|preset| preset.name)
51        .collect::<Vec<_>>()
52        .join(", ")
53}