Move RenameRule parse error message to a Display impl

This commit is contained in:
David Tolnay
2021-01-23 14:12:26 -08:00
parent 7db0982e58
commit 51d4563ed1
2 changed files with 18 additions and 42 deletions
+12
View File
@@ -5,6 +5,8 @@
#[allow(deprecated, unused_imports)]
use std::ascii::AsciiExt;
use std::fmt::{self, Display};
use self::RenameRule::*;
/// The different possible ways to change case of fields in a struct, or variants in an enum.
@@ -108,6 +110,16 @@ pub struct ParseError<'a> {
unknown: &'a str,
}
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,
)
}
}
#[test]
fn rename_variants() {
for &(original, lower, upper, camel, snake, screaming, kebab, screaming_kebab) in &[