Implement FromStr for Json
This commit is contained in:
parent
6ae5e92cc2
commit
954c3234a0
1 changed files with 13 additions and 3 deletions
|
@ -2166,6 +2166,12 @@ impl fmt::Show for Json {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::from_str::FromStr for Json {
|
||||||
|
fn from_str(s: &str) -> Option<Json> {
|
||||||
|
from_str(s).ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
@ -2180,9 +2186,7 @@ mod tests {
|
||||||
InvalidSyntax, InvalidNumber, EOFWhileParsingObject, EOFWhileParsingList,
|
InvalidSyntax, InvalidNumber, EOFWhileParsingObject, EOFWhileParsingList,
|
||||||
EOFWhileParsingValue, EOFWhileParsingString, KeyMustBeAString, ExpectedColon,
|
EOFWhileParsingValue, EOFWhileParsingString, KeyMustBeAString, ExpectedColon,
|
||||||
TrailingCharacters};
|
TrailingCharacters};
|
||||||
use std::f32;
|
use std::{f32, f64, io};
|
||||||
use std::f64;
|
|
||||||
use std::io;
|
|
||||||
use std::collections::TreeMap;
|
use std::collections::TreeMap;
|
||||||
|
|
||||||
#[deriving(PartialEq, Encodable, Decodable, Show)]
|
#[deriving(PartialEq, Encodable, Decodable, Show)]
|
||||||
|
@ -2215,6 +2219,12 @@ mod tests {
|
||||||
Object(d)
|
Object(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from_str_trait() {
|
||||||
|
let s = "null";
|
||||||
|
assert!(::std::from_str::from_str::<Json>(s).unwrap() == from_str(s).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_write_null() {
|
fn test_write_null() {
|
||||||
assert_eq!(Null.to_str().into_string(), "null".to_string());
|
assert_eq!(Null.to_str().into_string(), "null".to_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue