[meta] Add features to srcgen;

- Adds a compiler warning when the fmtln! macro isn't correctly used.
- Allow to add an empty line.
- Make the output of generated matches more beautiful, by having one
struct per line on the clause.
- Add a method to add match with doesn't read any data from fields.
- Make sure that the placeholder clause of a match is put at the end.
This commit is contained in:
Benjamin Bouvier
2019-03-11 17:12:03 +01:00
parent 68bda3a42d
commit 72b0d26ee9
2 changed files with 98 additions and 17 deletions

View File

@@ -152,13 +152,9 @@ fn gen_getter(setting: &Setting, fmt: &mut Formatter) {
fmt.indent(|fmt| {
let mut m = Match::new(format!("self.bytes[{}]", setting.byte_offset));
for (i, v) in values.iter().enumerate() {
m.arm(
format!("{}", i),
vec![],
format!("{}::{}", ty, camel_case(v)),
);
m.arm_no_fields(format!("{}", i), format!("{}::{}", ty, camel_case(v)));
}
m.arm("_", vec![], "panic!(\"Invalid enum value\")");
m.arm_no_fields("_", "panic!(\"Invalid enum value\")");
fmt.add_match(m);
});
fmtln!(fmt, "}");