derpscfg 0.8.0

A brief, incomplete, and mostly wrong derive implementation for scfg
Documentation
//! Extension of the "basic" example demonstrating the use of maps.
#![allow(unused_crate_dependencies)]
use std::collections::HashMap;

use derpscfg::{Error, prelude::*};

#[derive(Debug, Derpscfg)]
pub struct Model {
    // When using maps, the first parameter of a the directive will be used as
    // the key, so the type itself must no longer attempt to consume it!
    // #[scfg(param)]
    // pub name: String,
    pub max_speed: String,
    pub weight: String,
    pub lines_served: Vec<String>,
}

#[derive(Debug, Derpscfg)]
pub struct Train {
    #[scfg(param)]
    pub name: String,
    #[scfg(name = "model")]
    pub models: HashMap<String, Model>,
}

#[derive(Debug, Derpscfg)]
pub struct ScfgDemo {
    pub train: Train,
}

fn main() {
    static SCFG_DOC: &str = r#"
train "Shinkansen" {
	model "E5" {
		max-speed 320km/h
		weight 453.5t

		lines-served "Tōhoku" "Hokkaido"
	}

	model "E7" {
		max-speed 275km/h
		weight 540t

		lines-served "Hokuriku" "Jōetsu"
	}
}
"#;

    let demo = derpscfg::parse::<ScfgDemo>(SCFG_DOC);
    match demo {
        Ok(demo) => println!("{demo:?}"),
        // Unlike sets, where duplicate values are simply discarded, decoding
        // maps throws an error when duplicate keys are encountered, because it
        // often hints at underlying semantic issues.
        // Change the model "E7" to also be "E5" to see it in action.
        Err(Error::DuplicateKey(details)) => eprintln!("duplicate key: {details}"),
        Err(e) => eprintln!("error: {e}"),
    }
}