Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 93087ac

Browse files
committed
use new IO crate
1 parent 213ef7b commit 93087ac

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Diff for: src/json.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ use std::num::{Float, Int};
250250
use std::ops::Index;
251251
use std::str::FromStr;
252252
use std::string;
253-
use std::{char, f64, fmt, old_io, num, str};
253+
use std::{char, f64, fmt, io, num, str};
254254
use std;
255255
use unicode::str as unicode_str;
256256
use unicode::str::Utf16Item;
@@ -300,11 +300,11 @@ pub enum ErrorCode {
300300
NotUtf8,
301301
}
302302

303-
#[derive(Clone, Copy, PartialEq, Debug)]
303+
#[derive(Clone, PartialEq, Debug)]
304304
pub enum ParserError {
305305
/// msg, line, col
306306
SyntaxError(ErrorCode, usize, usize),
307-
IoError(old_io::IoErrorKind, &'static str),
307+
IoError(io::Error),
308308
}
309309

310310
// Builder and Parser have the same errors.
@@ -375,8 +375,8 @@ impl fmt::Debug for ErrorCode {
375375
}
376376
}
377377

378-
fn io_error_to_error(io: old_io::IoError) -> ParserError {
379-
IoError(io.kind, io.desc)
378+
fn io_error_to_error(err: io::Error) -> ParserError {
379+
IoError(err)
380380
}
381381

382382
impl StdError for DecoderError {
@@ -918,11 +918,15 @@ pub fn as_pretty_json<T: Encodable>(t: &T) -> AsPrettyJson<T> {
918918
}
919919

920920
impl Json {
921-
/// Decodes a json value from an `&mut old_io::Reader`
922-
pub fn from_reader(rdr: &mut old_io::Reader) -> Result<Self, BuilderError> {
923-
let contents = match rdr.read_to_end() {
924-
Ok(c) => c,
925-
Err(e) => return Err(io_error_to_error(e))
921+
/// Decodes a json value from an `&mut io::Read`
922+
pub fn from_reader(rdr: &mut io::Read) -> Result<Self, BuilderError> {
923+
let contents = {
924+
let mut c = Vec::new();
925+
match rdr.read_to_end(&mut c) {
926+
Ok(c) => c,
927+
Err(e) => return Err(io_error_to_error(e))
928+
}
929+
c
926930
};
927931
let s = match str::from_utf8(&contents).ok() {
928932
Some(s) => s,
@@ -1905,7 +1909,7 @@ impl<T: Iterator<Item = char>> Builder<T> {
19051909
self.bump();
19061910
match self.token {
19071911
None => {}
1908-
Some(Error(e)) => { return Err(e); }
1912+
Some(Error(ref e)) => { return Err(e.clone()); }
19091913
ref tok => { panic!("unexpected token {:?}", tok.clone()); }
19101914
}
19111915
result
@@ -1927,7 +1931,7 @@ impl<T: Iterator<Item = char>> Builder<T> {
19271931
swap(s, &mut temp);
19281932
Ok(Json::String(temp))
19291933
}
1930-
Some(Error(e)) => Err(e),
1934+
Some(Error(ref e)) => Err(e.clone()),
19311935
Some(ArrayStart) => self.build_array(),
19321936
Some(ObjectStart) => self.build_object(),
19331937
Some(ObjectEnd) => self.parser.error(InvalidSyntax),
@@ -1960,7 +1964,7 @@ impl<T: Iterator<Item = char>> Builder<T> {
19601964
loop {
19611965
match self.token {
19621966
Some(ObjectEnd) => { return Ok(Json::Object(values)); }
1963-
Some(Error(e)) => { return Err(e); }
1967+
Some(Error(ref e)) => { return Err(e.clone()); }
19641968
None => { break; }
19651969
_ => {}
19661970
}
@@ -3360,7 +3364,7 @@ mod tests {
33603364
#[test]
33613365
fn test_encode_hashmap_with_numeric_key() {
33623366
use std::str::from_utf8;
3363-
use std::old_io::Writer;
3367+
// use std::io::Write;
33643368
use std::collections::HashMap;
33653369
let mut hm: HashMap<usize, bool> = HashMap::new();
33663370
hm.insert(1, true);
@@ -3376,7 +3380,7 @@ mod tests {
33763380
#[test]
33773381
fn test_prettyencode_hashmap_with_numeric_key() {
33783382
use std::str::from_utf8;
3379-
use std::old_io::Writer;
3383+
// use std::io::Write;
33803384
use std::collections::HashMap;
33813385
let mut hm: HashMap<usize, bool> = HashMap::new();
33823386
hm.insert(1, true);

Diff for: src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Support code for encoding and decoding types.
1212
13-
#![feature(core, collections, unicode, old_io, std_misc, old_path, path, os)]
13+
#![feature(core, collections, unicode, old_io, io, std_misc, old_path, path, os)]
1414
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1515
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
1616
html_root_url = "http://doc.rust-lang.org/rustc-serialize/")]

0 commit comments

Comments
 (0)