Skip to content

No way to express named vector of enum children #38

@petervdonovan

Description

@petervdonovan

Minimal example that illustrates the problem:

#[test]
    fn test() {
        #[derive(knuffel::Decode)]
        struct Test {
            #[knuffel(children(name = "sorts"))]
            sort: Vec<ThisOrThat>
        }
        #[derive(knuffel::Decode)]
        enum ThisOrThat {
            This,
            That,
        }
        let parsed = match knuffel::parse::<Test>("example.kdl", r#"
sorts
"#) {
            Ok(parsed) => parsed,
            Err(e) => {
                panic!("{:?}", miette::Report::new(e))
            },
        };
    }

And the error is:

Error: 
  × expected one of `this`, `that`
  ╰─▶ expected one of `this`, `that`
   ╭─[example.kdl:1:1]
 1 │ 
 2 │ sorts
   · ──┬──
   ·   ╰── invalid value
   ╰────

The underlying problem is that the token "sorts" that is used to indicate what set of children it is is also being used as the same node that is supposed to indicate which enum variant. So in order for this to parse, it would be necessary for the name of the list of children to be the same as one of the enum variants, because that same token is being used for both purposes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions