From 981bf5f690d1d7c5cf3e1419ac7a7c86dbc7a4d5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 11 Mar 2015 15:24:14 -0700 Subject: Fallout of std::old_io deprecation --- src/libserialize/json.rs | 29 ++++++++++++++++------------- src/libserialize/lib.rs | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src/libserialize') diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 6fc56522c6a..d0ef89e811b 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -199,15 +199,17 @@ use self::DecoderError::*; use self::ParserState::*; use self::InternalStackElement::*; -use std; use std::collections::{HashMap, BTreeMap}; -use std::{char, f64, fmt, old_io, num, str}; +use std::io::prelude::*; +use std::io; use std::mem::{swap}; -use std::num::{Float, Int}; use std::num::FpCategory as Fp; +use std::num::{Float, Int}; +use std::ops::Index; use std::str::FromStr; use std::string; -use std::ops::Index; +use std::{char, f64, fmt, num, str}; +use std; use unicode::str as unicode_str; use unicode::str::Utf16Item; @@ -256,11 +258,11 @@ pub enum ErrorCode { NotUtf8, } -#[derive(Clone, Copy, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug)] pub enum ParserError { /// msg, line, col SyntaxError(ErrorCode, uint, uint), - IoError(old_io::IoErrorKind, &'static str), + IoError(io::ErrorKind, String), } // Builder and Parser have the same errors. @@ -331,8 +333,8 @@ impl fmt::Display for ErrorCode { } } -fn io_error_to_error(io: old_io::IoError) -> ParserError { - IoError(io.kind, io.desc) +fn io_error_to_error(io: io::Error) -> ParserError { + IoError(io.kind(), io.to_string()) } impl fmt::Display for ParserError { @@ -1982,7 +1984,7 @@ impl> Builder { self.bump(); match self.token { None => {} - Some(Error(e)) => { return Err(e); } + Some(Error(ref e)) => { return Err(e.clone()); } ref tok => { panic!("unexpected token {:?}", tok.clone()); } } result @@ -2004,7 +2006,7 @@ impl> Builder { swap(s, &mut temp); Ok(Json::String(temp)) } - Some(Error(e)) => Err(e), + Some(Error(ref e)) => Err(e.clone()), Some(ArrayStart) => self.build_array(), Some(ObjectStart) => self.build_object(), Some(ObjectEnd) => self.parser.error(InvalidSyntax), @@ -2037,7 +2039,7 @@ impl> Builder { loop { match self.token { Some(ObjectEnd) => { return Ok(Json::Object(values)); } - Some(Error(e)) => { return Err(e); } + Some(Error(ref e)) => { return Err(e.clone()); } None => { break; } _ => {} } @@ -2056,8 +2058,9 @@ impl> Builder { } /// Decodes a json value from an `&mut old_io::Reader` -pub fn from_reader(rdr: &mut old_io::Reader) -> Result { - let contents = match rdr.read_to_end() { +pub fn from_reader(rdr: &mut Read) -> Result { + let mut contents = Vec::new(); + match rdr.read_to_end(&mut contents) { Ok(c) => c, Err(e) => return Err(io_error_to_error(e)) }; diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 8d58ba99e13..49e44a6d455 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -31,7 +31,7 @@ Core encoding and decoding interfaces. #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(old_io)] +#![feature(io)] #![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] -- cgit 1.4.1-3-g733a5