Open LittleEntity opened 3 years ago
Yes, this seems like a defect in ructe. I'll try to fix it.
I guess it can be fixed here: https://github.com/kaj/ructe/blob/75b2e7da686abdd22bd2488e63f1528e3e16d313/src/templateexpression.rs#L210-L244
Unfortunatly I only have some experience with https://pest.rs/ . Nom seems to be a fine parsing library too. Maybe I will find some spare time this weekend to look into https://lib.rs/crates/nom. Maybe I can contribute in the future ^^.
Please take note there is more to the match syntax to explore: https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html
There are many cases I didn't know of before. For example the @
binding. It seems to be a huge task to parse every possible match syntax pattern correctly. I personally use this pattern as well:
enum Variation {
Structure {
id: usize,
name: String,
not_used: i32,
},
SimpleVariant,
}
fn main() {
let variation = Variation::Structure {
id: 42,
name: "an example for the great ructe lib 🦀".into(),
not_used: -123,
};
match variation {
Variation::Structure {
id,
name: the_name,
..
} => {
println!(r#"Object with ID {} has the name "{}""#, id, the_name);
}
Variation::SimpleVariant => {
println!("This is just a simple variant match");
}
}
}
Please consider documenting which patterns are explicitly implemented and tested. If the mentioned enum/struct patterns work, that would be great. If you cannot fix it, because of lack of time or whatever reason, I will try to make a good work around =) thankyou 🙏
Are you looking for help with this library of yours? If so I will check if I can take off some spare time to contribute to this lib.
I try to match the following enum with internal struct variants
with
The error message is:
this works:
In rust this works:
Am I doing something wrong? Is this a defect of the library?
I enjoy using ructe 🦀 thankyou for sharing 🙏