Merge pull request #1961 from serde-rs/renamerule

Provide list of recognized rename rules on parse error
This commit is contained in:
David Tolnay 2021-01-23 14:50:02 -08:00 committed by GitHub
commit 6670a309ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -5,7 +5,7 @@
#[allow(deprecated, unused_imports)]
use std::ascii::AsciiExt;
use std::fmt::{self, Display};
use std::fmt::{self, Debug, Display};
use self::RenameRule::*;
@ -120,11 +120,16 @@ 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 = ")?;
Debug::fmt(self.unknown, f)?;
f.write_str("`, expected one of ")?;
for (i, (name, _rule)) in RENAME_RULES.iter().enumerate() {
if i > 0 {
f.write_str(", ")?;
}
Debug::fmt(name, f)?;
}
Ok(())
}
}

View File

@ -1,4 +1,4 @@
error: unknown rename rule for #[serde(rename_all = "abc")]
error: unknown rename rule `rename_all = "abc"`, expected one of "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case", "SCREAMING-KEBAB-CASE"
--> $DIR/container_unknown_rename_rule.rs:4:22
|
4 | #[serde(rename_all = "abc")]

View File

@ -1,4 +1,4 @@
error: unknown rename rule for #[serde(rename_all = "abc")]
error: unknown rename rule `rename_all = "abc"`, expected one of "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case", "SCREAMING-KEBAB-CASE"
--> $DIR/variant_unknown_rename_rule.rs:5:26
|
5 | #[serde(rename_all = "abc")]