update for rustc

This commit is contained in:
Ty Overby 2015-04-02 12:24:05 -07:00
parent 6bc25f21db
commit e5d0c33acd
4 changed files with 14 additions and 15 deletions

View File

@ -3,7 +3,7 @@
#![crate_type = "dylib"] #![crate_type = "dylib"]
#![doc(html_logo_url = "./icon.png")] #![doc(html_logo_url = "./icon.png")]
#![feature(core, io, unicode)] #![feature(core, unicode)]
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate byteorder; extern crate byteorder;

View File

@ -2,8 +2,9 @@ use std::io::Read;
use std::io::Error as IoError; use std::io::Error as IoError;
use std::io::Result as IoResult; use std::io::Result as IoResult;
use std::num::{cast, NumCast}; use std::num::{cast, NumCast};
use std::error::{Error, FromError}; use std::error::Error;
use std::fmt; use std::fmt;
use std::convert::From;
use rustc_serialize::Decoder; 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 /// If decoding from a Buffer, assume that the buffer has been left
/// in an invalid state. /// in an invalid state.
#[derive(Eq, PartialEq, Clone, Debug)] #[derive(Debug)]
pub enum DecodingError { pub enum DecodingError {
/// If the error stems from the reader that is being used /// If the error stems from the reader that is being used
/// during decoding, that error will be stored and returned here. /// during decoding, that error will be stored and returned here.
@ -94,8 +95,8 @@ impl Error for DecodingError {
} }
} }
impl FromError<IoError> for DecodingError { impl From<IoError> for DecodingError {
fn from_error(err: IoError) -> DecodingError { fn from(err: IoError) -> DecodingError {
DecodingError::IoError(err) DecodingError::IoError(err)
} }
} }
@ -357,7 +358,7 @@ fn read_at_least<R: Read>(reader: &mut R, min: usize, buf: &mut [u8]) -> IoResul
use std::io::ErrorKind; use std::io::ErrorKind;
if min > buf.len() { if min > buf.len() {
return Err(IoError::new( return Err(IoError::new(
ErrorKind::InvalidInput, "the buffer is too short", None)); ErrorKind::InvalidInput, "the buffer is too short"));
} }
let mut read = 0; let mut read = 0;
@ -369,8 +370,7 @@ fn read_at_least<R: Read>(reader: &mut R, min: usize, buf: &mut [u8]) -> IoResul
zeroes += 1; zeroes += 1;
if zeroes >= 1000 { if zeroes >= 1000 {
return Err(IoError::new(ErrorKind::Other, return Err(IoError::new(ErrorKind::Other,
"no progress was made", "no progress was made"));
None ));
} }
} }
Ok(n) => { Ok(n) => {
@ -401,7 +401,7 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: usize, end: usize)
fn push_at_least<R: Read>(reader: &mut R, min: usize, len: usize, buf: &mut Vec<u8>) -> IoResult<usize> { fn push_at_least<R: Read>(reader: &mut R, min: usize, len: usize, buf: &mut Vec<u8>) -> IoResult<usize> {
use std::io::ErrorKind; use std::io::ErrorKind;
if min > len { 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(); let start_len = buf.len();

View File

@ -230,7 +230,8 @@ fn too_big_char_decode() {
let encoded = vec![0x41]; let encoded = vec![0x41];
let mut encoded_ref = &encoded[..]; let mut encoded_ref = &encoded[..];
let decoded: Result<char, _> = decode_from(&mut encoded_ref, Bounded(1)); let decoded: Result<char, _> = decode_from(&mut encoded_ref, Bounded(1));
assert_eq!(decoded, Ok('A')); assert!(decoded.is_ok());
assert_eq!(decoded.unwrap(), 'A');
} }
#[test] #[test]

View File

@ -2,7 +2,6 @@ use std::io::Write;
use std::io::Error as IoError; use std::io::Error as IoError;
use std::io::ErrorKind as IoErrorKind; use std::io::ErrorKind as IoErrorKind;
use std::error::Error; use std::error::Error;
use std::num::Int;
use std::fmt; use std::fmt;
use rustc_serialize::Encoder; use rustc_serialize::Encoder;
@ -14,7 +13,7 @@ pub type EncodingResult<T> = Result<T, EncodingError>;
/// An error that can be produced during encoding. /// An error that can be produced during encoding.
#[derive(Debug,Clone,PartialEq)] #[derive(Debug)]
pub enum EncodingError { pub enum EncodingError {
/// An error originating from the underlying `Writer`. /// An error originating from the underlying `Writer`.
IoError(IoError), IoError(IoError),
@ -43,8 +42,7 @@ fn wrap_io(err: ByteOrderError) -> EncodingError {
ByteOrderError::Io(ioe) => EncodingError::IoError(ioe), ByteOrderError::Io(ioe) => EncodingError::IoError(ioe),
ByteOrderError::UnexpectedEOF => EncodingError::IoError( ByteOrderError::UnexpectedEOF => EncodingError::IoError(
IoError::new(IoErrorKind::Other, IoError::new(IoErrorKind::Other,
"ByteOrder could not write to the buffer", "ByteOrder could not write to the buffer"))
None))
} }
} }
@ -166,7 +164,7 @@ impl<'a, W: Write> Encoder for EncoderWriter<'a, W> {
_: usize, _: usize,
f: F) -> EncodingResult<()> where f: F) -> EncodingResult<()> where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EncodingResult<()> { 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) { if v_id > (max_u32 as usize) {
panic!("Variant tag doesn't fit in a u32") panic!("Variant tag doesn't fit in a u32")
} }