[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:
@@ -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, "}");
|
||||
|
||||
Reference in New Issue
Block a user