Ignore underscore-prefixed fields in record builders

This commit is contained in:
Sam Mohr 2024-08-04 03:34:39 -07:00
parent 13f60cde09
commit cb8040f629
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
16 changed files with 336 additions and 140 deletions

View file

@ -428,9 +428,9 @@ fn is_multiline_assigned_field_help<T: Formattable>(afield: &AssignedField<'_, T
use self::AssignedField::*;
match afield {
RequiredValue(_, spaces, ann) | OptionalValue(_, spaces, ann) => {
!spaces.is_empty() || ann.value.is_multiline()
}
RequiredValue(_, spaces, ann)
| OptionalValue(_, spaces, ann)
| IgnoredValue(_, spaces, ann) => !spaces.is_empty() || ann.value.is_multiline(),
LabelOnly(_) => false,
AssignedField::SpaceBefore(_, _) | AssignedField::SpaceAfter(_, _) => true,
Malformed(text) => text.chars().any(|c| c == '\n'),
@ -483,6 +483,24 @@ fn format_assigned_field_help<T>(
buf.spaces(1);
ann.value.format(buf, indent);
}
IgnoredValue(name, spaces, ann) => {
if is_multiline {
buf.newline();
}
buf.indent(indent);
buf.push('_');
buf.push_str(name.value);
if !spaces.is_empty() {
fmt_spaces(buf, spaces.iter(), indent);
}
buf.spaces(separator_spaces);
buf.push(':');
buf.spaces(1);
ann.value.format(buf, indent);
}
LabelOnly(name) => {
if is_multiline {
buf.newline();

View file

@ -1529,6 +1529,23 @@ fn format_assigned_field_multiline<T>(
ann.value.format(buf, indent);
buf.push(',');
}
IgnoredValue(name, spaces, ann) => {
buf.newline();
buf.indent(indent);
buf.push('_');
buf.push_str(name.value);
if !spaces.is_empty() {
fmt_spaces(buf, spaces.iter(), indent);
buf.indent(indent);
}
buf.push_str(separator_prefix);
buf.push_str(":");
buf.spaces(1);
ann.value.format(buf, indent);
buf.push(',');
}
LabelOnly(name) => {
buf.newline();
buf.indent(indent);