From e5d0c33acde2c2ad372ff72b39faacb1e91c22f6 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Thu, 2 Apr 2015 12:24:05 -0700 Subject: [PATCH] update for rustc --- src/lib.rs | 2 +- src/reader.rs | 16 ++++++++-------- src/test.rs | 3 ++- src/writer.rs | 8 +++----- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 71b91a1..8f1edfe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ #![crate_type = "dylib"] #![doc(html_logo_url = "./icon.png")] -#![feature(core, io, unicode)] +#![feature(core, unicode)] extern crate rustc_serialize; extern crate byteorder; diff --git a/src/reader.rs b/src/reader.rs index 7e9fb45..5c5d127 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2,8 +2,9 @@ use std::io::Read; use std::io::Error as IoError; use std::io::Result as IoResult; use std::num::{cast, NumCast}; -use std::error::{Error, FromError}; +use std::error::Error; use std::fmt; +use std::convert::From; use rustc_serialize::Decoder; @@ -35,7 +36,7 @@ impl fmt::Display for InvalidEncoding { /// /// If decoding from a Buffer, assume that the buffer has been left /// in an invalid state. -#[derive(Eq, PartialEq, Clone, Debug)] +#[derive(Debug)] pub enum DecodingError { /// If the error stems from the reader that is being used /// during decoding, that error will be stored and returned here. @@ -94,8 +95,8 @@ impl Error for DecodingError { } } -impl FromError for DecodingError { - fn from_error(err: IoError) -> DecodingError { +impl From for DecodingError { + fn from(err: IoError) -> DecodingError { DecodingError::IoError(err) } } @@ -357,7 +358,7 @@ fn read_at_least(reader: &mut R, min: usize, buf: &mut [u8]) -> IoResul use std::io::ErrorKind; if min > buf.len() { return Err(IoError::new( - ErrorKind::InvalidInput, "the buffer is too short", None)); + ErrorKind::InvalidInput, "the buffer is too short")); } let mut read = 0; @@ -369,8 +370,7 @@ fn read_at_least(reader: &mut R, min: usize, buf: &mut [u8]) -> IoResul zeroes += 1; if zeroes >= 1000 { return Err(IoError::new(ErrorKind::Other, - "no progress was made", - None )); + "no progress was made")); } } Ok(n) => { @@ -401,7 +401,7 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec, start: usize, end: usize) fn push_at_least(reader: &mut R, min: usize, len: usize, buf: &mut Vec) -> IoResult { use std::io::ErrorKind; if min > len { - return Err(IoError::new(ErrorKind::InvalidInput, "the buffer is too short", None)); + return Err(IoError::new(ErrorKind::InvalidInput, "the buffer is too short")); } let start_len = buf.len(); diff --git a/src/test.rs b/src/test.rs index 84cb275..6de7760 100644 --- a/src/test.rs +++ b/src/test.rs @@ -230,7 +230,8 @@ fn too_big_char_decode() { let encoded = vec![0x41]; let mut encoded_ref = &encoded[..]; let decoded: Result = decode_from(&mut encoded_ref, Bounded(1)); - assert_eq!(decoded, Ok('A')); + assert!(decoded.is_ok()); + assert_eq!(decoded.unwrap(), 'A'); } #[test] diff --git a/src/writer.rs b/src/writer.rs index e21052e..c1da743 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -2,7 +2,6 @@ use std::io::Write; use std::io::Error as IoError; use std::io::ErrorKind as IoErrorKind; use std::error::Error; -use std::num::Int; use std::fmt; use rustc_serialize::Encoder; @@ -14,7 +13,7 @@ pub type EncodingResult = Result; /// An error that can be produced during encoding. -#[derive(Debug,Clone,PartialEq)] +#[derive(Debug)] pub enum EncodingError { /// An error originating from the underlying `Writer`. IoError(IoError), @@ -43,8 +42,7 @@ fn wrap_io(err: ByteOrderError) -> EncodingError { ByteOrderError::Io(ioe) => EncodingError::IoError(ioe), ByteOrderError::UnexpectedEOF => EncodingError::IoError( IoError::new(IoErrorKind::Other, - "ByteOrder could not write to the buffer", - None)) + "ByteOrder could not write to the buffer")) } } @@ -166,7 +164,7 @@ impl<'a, W: Write> Encoder for EncoderWriter<'a, W> { _: usize, f: F) -> EncodingResult<()> where F: FnOnce(&mut EncoderWriter<'a, W>) -> EncodingResult<()> { - let max_u32: u32 = Int::max_value(); + let max_u32: u32 = ::std::u32::MAX; if v_id > (max_u32 as usize) { panic!("Variant tag doesn't fit in a u32") }