`std::fmt::String` impls.
This commit is contained in:
parent
54061d5eff
commit
eb933c9f89
|
|
@ -1,6 +1,7 @@
|
|||
use std::io::{Buffer, Reader, IoError};
|
||||
use std::num::{cast, NumCast};
|
||||
use std::error::{Error, FromError};
|
||||
use std::fmt;
|
||||
|
||||
use rustc_serialize::Decoder;
|
||||
|
||||
|
|
@ -12,6 +13,17 @@ pub struct InvalidEncoding {
|
|||
detail: Option<String>,
|
||||
}
|
||||
|
||||
impl fmt::String for InvalidEncoding {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
InvalidEncoding { detail: None, desc } =>
|
||||
write!(fmt, "{}", desc),
|
||||
InvalidEncoding { detail: Some(ref detail), desc } =>
|
||||
write!(fmt, "{} ({})", desc, detail)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that can be produced during decoding.
|
||||
///
|
||||
/// If decoding from a Buffer, assume that the buffer has been left
|
||||
|
|
@ -31,6 +43,19 @@ pub enum DecodingError {
|
|||
SizeLimit
|
||||
}
|
||||
|
||||
impl fmt::String for DecodingError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
DecodingError::IoError(ref ioerr) =>
|
||||
write!(fmt, "IoError: {}", ioerr),
|
||||
DecodingError::InvalidEncoding(ref ib) =>
|
||||
write!(fmt, "InvalidEncoding: {}", ib),
|
||||
DecodingError::SizeLimit =>
|
||||
write!(fmt, "SizeLimit")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type DecodingResult<T> = Result<T, DecodingError>;
|
||||
|
||||
fn wrap_io(err: IoError) -> DecodingError {
|
||||
|
|
|
|||
Loading…
Reference in New Issue