Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive for KDL #26

Closed
tailhook opened this issue Oct 17, 2021 · 1 comment
Closed

Derive for KDL #26

tailhook opened this issue Oct 17, 2021 · 1 comment

Comments

@tailhook
Copy link

tailhook commented Oct 17, 2021

Hi! I think it's worth to make a derive macro for decoding and validating KDL. This is a bit different from #17, as that has some specific mapping between KDL and serde structure. And I'm proposing something, more like in clap.

So for this example from help (adjusted a bit):

contents {
  section "First section" style="emphasized" {
    paragraph "This is the first paragraph"
    paragraph "This is the second paragraph"
  }
}

You could have structures like:

#[derive(kdl::Decode)]
struct Contents {
    #[kdl(children, filter(node_name="section"))]
    sections: Vec<Section>
}

#[derive(kdl::Decode)]
struct Section {
    #[kdl(argument)]
    title: String,
    #[kdl(property, default="normal")]
    style: String,
    #[kdl(children)]
    children: Vec<Block>
}

#[derive(kdl::Decode)]
enum Block {
    #[kdl(node_name="paragraph")]
    Paragraph(String),
    #[kdl(node_name="figure")]
    Figure(Figure),
}

And this could serve as both: more convenient structure to work with data and to validate that there are no extra arguments and properties (unless there is an explicit extension point) and types of all arguments and properties are correct.

What do you think?

@tailhook
Copy link
Author

tailhook commented Feb 7, 2022

Implemented in https://docs.rs/knuffel/ (although, that also uses its own parser, so not directly related to this project)

@tailhook tailhook closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant