forked from extern/nushell
Preserve order when serializing/deserialize json by default. (#3126)
This commit is contained in:
committed by
GitHub
parent
9c375b33a6
commit
0b71e45072
@ -18,24 +18,6 @@ pub enum ErrorCode {
|
||||
/// Catchall for syntax error messages
|
||||
Custom(String),
|
||||
|
||||
/// Incorrect type from value
|
||||
InvalidType(de::Type),
|
||||
|
||||
/// Incorrect value
|
||||
InvalidValue(String),
|
||||
|
||||
/// Invalid length
|
||||
InvalidLength(usize),
|
||||
|
||||
/// Unknown variant in an enum.
|
||||
UnknownVariant(String),
|
||||
|
||||
/// Unknown field in struct.
|
||||
UnknownField(String),
|
||||
|
||||
/// Struct is missing a field.
|
||||
MissingField(&'static str),
|
||||
|
||||
/// EOF while parsing a list.
|
||||
EOFWhileParsingList,
|
||||
|
||||
@ -94,12 +76,6 @@ impl fmt::Debug for ErrorCode {
|
||||
|
||||
match *self {
|
||||
ErrorCode::Custom(ref msg) => write!(f, "{}", msg),
|
||||
ErrorCode::InvalidType(ref ty) => write!(f, "invalid type: {:?}", ty),
|
||||
ErrorCode::InvalidValue(ref msg) => write!(f, "invalid value: {}", msg),
|
||||
ErrorCode::InvalidLength(ref len) => write!(f, "invalid value length {}", len),
|
||||
ErrorCode::UnknownVariant(ref variant) => write!(f, "unknown variant \"{}\"", variant),
|
||||
ErrorCode::UnknownField(ref field) => write!(f, "unknown field \"{}\"", field),
|
||||
ErrorCode::MissingField(ref field) => write!(f, "missing field \"{}\"", field),
|
||||
ErrorCode::EOFWhileParsingList => "EOF while parsing a list".fmt(f),
|
||||
ErrorCode::EOFWhileParsingObject => "EOF while parsing an object".fmt(f),
|
||||
ErrorCode::EOFWhileParsingString => "EOF while parsing a string".fmt(f),
|
||||
@ -173,69 +149,16 @@ impl From<FromUtf8Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<de::value::Error> for Error {
|
||||
fn from(error: de::value::Error) -> Error {
|
||||
match error {
|
||||
de::value::Error::Custom(e) => Error::Syntax(ErrorCode::Custom(e), 0, 0),
|
||||
de::value::Error::EndOfStream => de::Error::end_of_stream(),
|
||||
de::value::Error::InvalidType(ty) => Error::Syntax(ErrorCode::InvalidType(ty), 0, 0),
|
||||
de::value::Error::InvalidValue(msg) => {
|
||||
Error::Syntax(ErrorCode::InvalidValue(msg), 0, 0)
|
||||
}
|
||||
de::value::Error::InvalidLength(len) => {
|
||||
Error::Syntax(ErrorCode::InvalidLength(len), 0, 0)
|
||||
}
|
||||
de::value::Error::UnknownVariant(variant) => {
|
||||
Error::Syntax(ErrorCode::UnknownVariant(variant), 0, 0)
|
||||
}
|
||||
de::value::Error::UnknownField(field) => {
|
||||
Error::Syntax(ErrorCode::UnknownField(field), 0, 0)
|
||||
}
|
||||
de::value::Error::MissingField(field) => {
|
||||
Error::Syntax(ErrorCode::MissingField(field), 0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Error for Error {
|
||||
fn custom<T: Into<String>>(msg: T) -> Error {
|
||||
Error::Syntax(ErrorCode::Custom(msg.into()), 0, 0)
|
||||
}
|
||||
|
||||
fn end_of_stream() -> Error {
|
||||
Error::Syntax(ErrorCode::EOFWhileParsingValue, 0, 0)
|
||||
}
|
||||
|
||||
fn invalid_type(ty: de::Type) -> Error {
|
||||
Error::Syntax(ErrorCode::InvalidType(ty), 0, 0)
|
||||
}
|
||||
|
||||
fn invalid_value(msg: &str) -> Error {
|
||||
Error::Syntax(ErrorCode::InvalidValue(msg.to_owned()), 0, 0)
|
||||
}
|
||||
|
||||
fn invalid_length(len: usize) -> Error {
|
||||
Error::Syntax(ErrorCode::InvalidLength(len), 0, 0)
|
||||
}
|
||||
|
||||
fn unknown_variant(variant: &str) -> Error {
|
||||
Error::Syntax(ErrorCode::UnknownVariant(String::from(variant)), 0, 0)
|
||||
}
|
||||
|
||||
fn unknown_field(field: &str) -> Error {
|
||||
Error::Syntax(ErrorCode::UnknownField(String::from(field)), 0, 0)
|
||||
}
|
||||
|
||||
fn missing_field(field: &'static str) -> Error {
|
||||
Error::Syntax(ErrorCode::MissingField(field), 0, 0)
|
||||
fn custom<T: fmt::Display>(msg: T) -> Error {
|
||||
Error::Syntax(ErrorCode::Custom(msg.to_string()), 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ser::Error for Error {
|
||||
/// Raised when there is general error when deserializing a type.
|
||||
fn custom<T: Into<String>>(msg: T) -> Error {
|
||||
Error::Syntax(ErrorCode::Custom(msg.into()), 0, 0)
|
||||
fn custom<T: fmt::Display>(msg: T) -> Error {
|
||||
Error::Syntax(ErrorCode::Custom(msg.to_string()), 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user