From bc78fe9635462b78cf767ce625b9e0472b6e15db Mon Sep 17 00:00:00 2001 From: Stanislav Panferov Date: Tue, 3 May 2016 14:18:54 +0300 Subject: [PATCH] feat(value): impl Display and FromStr traits --- json/src/value.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/json/src/value.rs b/json/src/value.rs index efffb92..58e1592 100644 --- a/json/src/value.rs +++ b/json/src/value.rs @@ -422,6 +422,21 @@ impl fmt::Debug for Value { } } +impl fmt::Display for Value { + /// Serializes a json value into a string + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut wr = WriterFormatter { inner: f }; + super::ser::to_writer(&mut wr, self).map_err(|_| fmt::Error) + } +} + +impl str::FromStr for Value { + type Err = Error; + fn from_str(s: &str) -> Result { + super::de::from_str(s) + } +} + #[derive(Debug)] enum State { Value(Value),