File: simple.rs

package info (click to toggle)
rust-knuffel 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 364 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::io::Read;

use miette::IntoDiagnostic;


#[derive(knuffel::Decode, Debug)]
#[allow(dead_code)]
struct Plugin {
    #[knuffel(argument)]
    name: String,
    #[knuffel(property)]
    url: String,
    #[knuffel(child, unwrap(argument))]
    version: String,
}

#[derive(knuffel::Decode, Debug)]
#[allow(dead_code)]
struct Config {
    #[knuffel(child, unwrap(argument))]
    version: String,
    #[knuffel(children(name="plugin"))]
    plugins: Vec<Plugin>,
}

fn main() -> miette::Result<()> {
    let mut buf = String::new();
    println!("Please type KDL document, press Return, Ctrl+D to finish");
    std::io::stdin().read_to_string(&mut buf).into_diagnostic()?;
    let cfg: Config = knuffel::parse("<stdin>", &buf)?;
    println!("{:#?}", cfg);
    Ok(())
}