Skip to content

Commit 46faaf2

Browse files
committed
Remove unreachable when implementing Display for ser::Error.
1 parent feb4856 commit 46faaf2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/de/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,32 @@ impl de::Error for Error {
548548
}
549549

550550
impl fmt::Display for Error {
551-
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
552-
unreachable!()
551+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
552+
write!(f, "{}", match self {
553+
Error::EofWhileParsingList => "EOF while parsing a list.",
554+
Error::EofWhileParsingObject => "EOF while parsing an object.",
555+
Error::EofWhileParsingString => "EOF while parsing a string.",
556+
Error::EofWhileParsingValue => "EOF while parsing a JSON value.",
557+
Error::ExpectedColon => "Expected this character to be a `':'`.",
558+
Error::ExpectedListCommaOrEnd => "Expected this character to be either a `','` or\
559+
a \
560+
`']'`.",
561+
Error::ExpectedObjectCommaOrEnd => "Expected this character to be either a `','` \
562+
or a \
563+
`'}'`.",
564+
Error::ExpectedSomeIdent => "Expected to parse either a `true`, `false`, or a \
565+
`null`.",
566+
Error::ExpectedSomeValue => "Expected this character to start a JSON value.",
567+
Error::InvalidNumber => "Invalid number.",
568+
Error::InvalidType => "Invalid type",
569+
Error::InvalidUnicodeCodePoint => "Invalid unicode code point.",
570+
Error::KeyMustBeAString => "Object key is not a string.",
571+
Error::TrailingCharacters => "JSON has non-whitespace trailing characters after \
572+
the \
573+
value.",
574+
Error::TrailingComma => "JSON has a comma after the last value in an array or map.",
575+
_ => "Invalid JSON"
576+
})
553577
}
554578
}
555579

src/ser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl ::std::error::Error for Error {
4646

4747

4848
impl fmt::Display for Error {
49-
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
50-
unreachable!()
49+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50+
write!(f, "Buffer is full")
5151
}
5252
}
5353

0 commit comments

Comments
 (0)