commit
32f772328e
|
|
@ -13,7 +13,7 @@ pub struct InvalidEncoding {
|
||||||
detail: Option<String>,
|
detail: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::String for InvalidEncoding {
|
impl fmt::Display for InvalidEncoding {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
InvalidEncoding { detail: None, desc } =>
|
InvalidEncoding { detail: None, desc } =>
|
||||||
|
|
@ -43,7 +43,7 @@ pub enum DecodingError {
|
||||||
SizeLimit
|
SizeLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::String for DecodingError {
|
impl fmt::Display for DecodingError {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
DecodingError::IoError(ref ioerr) =>
|
DecodingError::IoError(ref ioerr) =>
|
||||||
|
|
@ -71,10 +71,10 @@ impl Error for DecodingError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detail(&self) -> Option<String> {
|
fn cause(&self) -> Option<&Error> {
|
||||||
match *self {
|
match *self {
|
||||||
DecodingError::IoError(ref err) => err.detail(),
|
DecodingError::IoError(ref err) => err.cause(),
|
||||||
DecodingError::InvalidEncoding(ref ib) => ib.detail.clone(),
|
DecodingError::InvalidEncoding(_) => None,
|
||||||
DecodingError::SizeLimit => None
|
DecodingError::SizeLimit => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
extern crate "rustc-serialize" as serialize;
|
extern crate "rustc-serialize" as serialize;
|
||||||
|
|
||||||
use std::fmt::Show;
|
use std::fmt::Debug;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use rustc_serialize::{
|
use rustc_serialize::{
|
||||||
|
|
@ -20,7 +20,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use super::SizeLimit::{Infinite, Bounded};
|
use super::SizeLimit::{Infinite, Bounded};
|
||||||
|
|
||||||
fn the_same<'a, V>(element: V) where V: Encodable, V: Decodable, V: PartialEq, V: Show {
|
fn the_same<'a, V>(element: V) where V: Encodable, V: Decodable, V: PartialEq, V: Debug {
|
||||||
assert!(element == decode(encode(&element, Infinite).unwrap().as_slice()).unwrap());
|
assert!(element == decode(encode(&element, Infinite).unwrap().as_slice()).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::io::{Writer, IoError};
|
use std::io::{Writer, IoError};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::num::Int;
|
use std::num::Int;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use rustc_serialize::Encoder;
|
use rustc_serialize::Encoder;
|
||||||
|
|
||||||
|
|
@ -10,7 +11,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(Show)]
|
#[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),
|
||||||
|
|
@ -39,6 +40,15 @@ fn wrap_io(err: IoError) -> EncodingError {
|
||||||
EncodingError::IoError(err)
|
EncodingError::IoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for EncodingError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
match *self {
|
||||||
|
EncodingError::IoError(ref err) => write!(f, "IoError: {}", err),
|
||||||
|
EncodingError::SizeLimit => write!(f, "SizeLimit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Error for EncodingError {
|
impl Error for EncodingError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
@ -47,9 +57,9 @@ impl Error for EncodingError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detail(&self) -> Option<String> {
|
fn cause(&self) -> Option<&Error> {
|
||||||
match *self {
|
match *self {
|
||||||
EncodingError::IoError(ref err) => err.detail(),
|
EncodingError::IoError(ref err) => err.cause(),
|
||||||
EncodingError::SizeLimit => None
|
EncodingError::SizeLimit => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,8 +231,8 @@ impl<'a, W: Writer> Encoder for EncoderWriter<'a, W> {
|
||||||
try!(self.emit_usize(len));
|
try!(self.emit_usize(len));
|
||||||
f(self)
|
f(self)
|
||||||
}
|
}
|
||||||
fn emit_map_elt_key<F>(&mut self, _: usize, mut f: F) -> EncodingResult<()> where
|
fn emit_map_elt_key<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
||||||
F: FnMut(&mut EncoderWriter<'a, W>) -> EncodingResult<()> {
|
F: FnOnce(&mut EncoderWriter<'a, W>) -> EncodingResult<()> {
|
||||||
f(self)
|
f(self)
|
||||||
}
|
}
|
||||||
fn emit_map_elt_val<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
fn emit_map_elt_val<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
||||||
|
|
@ -361,8 +371,8 @@ impl Encoder for SizeChecker {
|
||||||
try!(self.emit_usize(len));
|
try!(self.emit_usize(len));
|
||||||
f(self)
|
f(self)
|
||||||
}
|
}
|
||||||
fn emit_map_elt_key<F>(&mut self, _: usize, mut f: F) -> EncodingResult<()> where
|
fn emit_map_elt_key<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
||||||
F: FnMut(&mut SizeChecker) -> EncodingResult<()> {
|
F: FnOnce(&mut SizeChecker) -> EncodingResult<()> {
|
||||||
f(self)
|
f(self)
|
||||||
}
|
}
|
||||||
fn emit_map_elt_val<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
fn emit_map_elt_val<F>(&mut self, _: usize, f: F) -> EncodingResult<()> where
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue