Auto merge of #63 - s-panferov:feature/traits, r=erickt

feat(value): impl Display and FromStr traits

Refs #62

I can add some tests, but implementation seems trivial. Tests fail on `nightly`, but this seems unrelated.
This commit is contained in:
Homu 2016-05-13 18:07:12 +09:00
commit fc9a5df6b6

View File

@ -464,6 +464,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<Value, Error> {
super::de::from_str(s)
}
}
#[derive(Debug)]
enum State {
Value(Value),