Uncomment more code.

This commit is contained in:
Erick Tryzelaar 2014-05-30 22:56:08 -07:00
parent 8526b9c480
commit 5bbe89197e

22
json.rs
View File

@ -566,10 +566,11 @@ impl fmt::Show for ErrorCode {
} }
} }
/*
fn io_error_to_error(io: io::IoError) -> ParserError { fn io_error_to_error(io: io::IoError) -> ParserError {
IoError(io.kind, io.desc) IoError(io.kind, io.desc)
} }
*/
pub type EncodeResult = io::IoResult<()>; pub type EncodeResult = io::IoResult<()>;
@ -2045,6 +2046,13 @@ pub fn from_iter<
} }
} }
/// Decodes a json value from a string
pub fn from_str<
'a,
T: de::Deserializable<ParserError, Parser<str::Chars<'a>>>
>(s: &'a str) -> Result<T, BuilderError> {
from_iter(s.chars())
}
/// Decodes a json value from a `Json`. /// Decodes a json value from a `Json`.
pub fn from_json< pub fn from_json<
@ -2540,7 +2548,7 @@ mod tests {
use self::test::Bencher; use self::test::Bencher;
use super::{Json, String, List, Object}; use super::{Json, String, List, Object};
use super::{Parser, ParserError, from_iter}; use super::{Parser, ParserError, from_iter, from_str};
use super::{JsonDeserializer, from_json, ToJson}; use super::{JsonDeserializer, from_json, ToJson};
use super::{ use super::{
EOFWhileParsingList, EOFWhileParsingList,
@ -3973,6 +3981,7 @@ mod tests {
assert!(stack.get(0) == Index(1)); assert!(stack.get(0) == Index(1));
assert!(stack.get(1) == Key("foo")); assert!(stack.get(1) == Key("foo"));
} }
*/
#[bench] #[bench]
fn bench_streaming_small(b: &mut Bencher) { fn bench_streaming_small(b: &mut Bencher) {
@ -3998,21 +4007,21 @@ mod tests {
#[bench] #[bench]
fn bench_small(b: &mut Bencher) { fn bench_small(b: &mut Bencher) {
b.iter( || { b.iter( || {
let _ = from_str(r#"{ let _: Json = from_str(r#"{
"a": 1.0, "a": 1.0,
"b": [ "b": [
true, true,
"foo\nbar", "foo\nbar",
{ "c": {"d": null} } { "c": {"d": null} }
] ]
}"#); }"#).unwrap();
}); });
} }
fn big_json() -> String { fn big_json() -> String {
let mut src = "[\n".to_string(); let mut src = "[\n".to_string();
for _ in range(0, 500) { for _ in range(0, 500) {
src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \ src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e":
[1,2,3]},"#); [1,2,3]},"#);
} }
src.push_str("{}]"); src.push_str("{}]");
@ -4035,7 +4044,6 @@ mod tests {
#[bench] #[bench]
fn bench_large(b: &mut Bencher) { fn bench_large(b: &mut Bencher) {
let src = big_json(); let src = big_json();
b.iter( || { let _ = from_str(src.as_slice()); }); b.iter( || { let _: Json = from_str(src.as_slice()).unwrap(); });
} }
*/
} }