mirror of
https://github.com/serde-rs/json.git
synced 2026-01-20 15:45:54 +00:00
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:
commit
fc9a5df6b6
@ -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),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user