Merge pull request #426 from serde-rs/display

impl Display for de::Type
This commit is contained in:
David Tolnay 2016-07-07 00:59:17 -07:00 committed by GitHub
commit 67d86dcc4f

View File

@ -8,6 +8,8 @@ use error;
#[cfg(all(not(feature = "std"), feature = "collections"))] #[cfg(all(not(feature = "std"), feature = "collections"))]
use collections::{String, Vec}; use collections::{String, Vec};
use core::fmt;
pub mod impls; pub mod impls;
pub mod value; pub mod value;
mod from_primitive; mod from_primitive;
@ -169,6 +171,46 @@ pub enum Type {
Bytes, Bytes,
} }
impl fmt::Display for Type {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let display = match *self {
Type::Bool => "bool",
Type::Usize => "usize",
Type::U8 => "u8",
Type::U16 => "u16",
Type::U32 => "u32",
Type::U64 => "u64",
Type::Isize => "isize",
Type::I8 => "i8",
Type::I16 => "i16",
Type::I32 => "i32",
Type::I64 => "i64",
Type::F32 => "f32",
Type::F64 => "f64",
Type::Char => "char",
Type::Str => "str",
Type::String => "string",
Type::Unit => "unit",
Type::Option => "option",
Type::Seq => "seq",
Type::Map => "map",
Type::UnitStruct => "unit struct",
Type::NewtypeStruct => "newtype struct",
Type::TupleStruct => "tuple struct",
Type::Struct => "struct",
Type::FieldName => "field name",
Type::Tuple => "tuple",
Type::Enum => "enum",
Type::VariantName => "variant name",
Type::StructVariant => "struct variant",
Type::TupleVariant => "tuple variant",
Type::UnitVariant => "unit variant",
Type::Bytes => "bytes",
};
display.fmt(formatter)
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// `Deserialize` represents a type that can be deserialized. /// `Deserialize` represents a type that can be deserialized.