Provide list of recognized rename rules on parse error

This commit is contained in:
David Tolnay
2021-01-23 14:36:52 -08:00
parent eaccae2c46
commit 4e002ece07
3 changed files with 14 additions and 7 deletions
+12 -5
View File
@@ -120,11 +120,18 @@ pub struct ParseError<'a> {
impl<'a> Display for ParseError<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"unknown rename rule for #[serde(rename_all = {:?})]",
self.unknown,
)
f.write_str("unknown rename rule `rename_all = \"")?;
self.unknown.escape_debug().fmt(f)?;
f.write_str("\"`, expected one of ")?;
for (i, (name, _rule)) in RENAME_RULES.iter().enumerate() {
if i > 0 {
f.write_str(", ")?;
}
f.write_str("\"")?;
name.escape_debug().fmt(f)?;
f.write_str("\"")?;
}
Ok(())
}
}