From 48eaf988bc353c09b7ef556464ebe2beb33afdcd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 22 Jan 2017 05:02:24 -0800 Subject: [PATCH] Add free-form option for Unexpected --- serde/src/de/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 6fca1bc4..967af350 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -269,6 +269,13 @@ pub enum Unexpected<'a> { /// The input contained a struct variant that was not expected. StructVariant, + + /// A message stating what uncategorized thing the input contained that was + /// not expected. + /// + /// The message should be a noun or noun phrase, not capitalized and without + /// a period. An example message is "unoriginal superhero". + Other(&'a str), } impl<'a> fmt::Display for Unexpected<'a> { @@ -292,6 +299,7 @@ impl<'a> fmt::Display for Unexpected<'a> { NewtypeVariant => write!(formatter, "newtype variant"), TupleVariant => write!(formatter, "tuple variant"), StructVariant => write!(formatter, "struct variant"), + Other(other) => formatter.write_str(other), } } }