Add Error impls to a few key error types
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
//! Base64 binary-to-text encoding
|
//! Base64 binary-to-text encoding
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
use std::error;
|
||||||
|
|
||||||
/// Available encoding character sets
|
/// Available encoding character sets
|
||||||
pub enum CharacterSet {
|
pub enum CharacterSet {
|
||||||
@@ -178,6 +179,19 @@ impl fmt::Show for FromBase64Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl error::Error for FromBase64Error {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
InvalidBase64Byte(_, _) => "invalid character",
|
||||||
|
InvalidBase64Length => "invalid length",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail(&self) -> Option<String> {
|
||||||
|
Some(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> FromBase64 for &'a str {
|
impl<'a> FromBase64 for &'a str {
|
||||||
/**
|
/**
|
||||||
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
|
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
//! Hex binary-to-text encoding
|
//! Hex binary-to-text encoding
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
use std::error;
|
||||||
|
|
||||||
/// A trait for converting a value to hexadecimal encoding
|
/// A trait for converting a value to hexadecimal encoding
|
||||||
pub trait ToHex {
|
pub trait ToHex {
|
||||||
@@ -77,6 +78,20 @@ impl fmt::Show for FromHexError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl error::Error for FromHexError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
InvalidHexCharacter(_, _) => "invalid character",
|
||||||
|
InvalidHexLength => "invalid length",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail(&self) -> Option<String> {
|
||||||
|
Some(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a> FromHex for &'a str {
|
impl<'a> FromHex for &'a str {
|
||||||
/**
|
/**
|
||||||
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
|
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
|
||||||
|
|||||||
@@ -313,6 +313,11 @@ fn io_error_to_error(io: io::IoError) -> ParserError {
|
|||||||
IoError(io.kind, io.desc)
|
IoError(io.kind, io.desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for DecoderError {
|
||||||
|
fn description(&self) -> &str { "decoder error" }
|
||||||
|
fn detail(&self) -> Option<std::string::String> { Some(self.to_string()) }
|
||||||
|
}
|
||||||
|
|
||||||
pub type EncodeResult = io::IoResult<()>;
|
pub type EncodeResult = io::IoResult<()>;
|
||||||
pub type DecodeResult<T> = Result<T, DecoderError>;
|
pub type DecodeResult<T> = Result<T, DecoderError>;
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,9 @@ responding to errors that may occur while attempting to read the numbers.
|
|||||||
#![deny(unused_must_use)]
|
#![deny(unused_must_use)]
|
||||||
|
|
||||||
use char::Char;
|
use char::Char;
|
||||||
|
use clone::Clone;
|
||||||
use default::Default;
|
use default::Default;
|
||||||
|
use error::{FromError, Error};
|
||||||
use fmt;
|
use fmt;
|
||||||
use int;
|
use int;
|
||||||
use iter::Iterator;
|
use iter::Iterator;
|
||||||
@@ -433,6 +435,22 @@ impl fmt::Show for IoError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error for IoError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
self.desc
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail(&self) -> Option<String> {
|
||||||
|
self.detail.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromError<IoError> for Box<Error> {
|
||||||
|
fn from_error(err: IoError) -> Box<Error> {
|
||||||
|
box err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A list specifying general categories of I/O error.
|
/// A list specifying general categories of I/O error.
|
||||||
#[deriving(PartialEq, Eq, Clone, Show)]
|
#[deriving(PartialEq, Eq, Clone, Show)]
|
||||||
pub enum IoErrorKind {
|
pub enum IoErrorKind {
|
||||||
|
|||||||
@@ -32,11 +32,13 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
|
use error::{FromError, Error};
|
||||||
use fmt;
|
use fmt;
|
||||||
use io::{IoResult, IoError};
|
use io::{IoResult, IoError};
|
||||||
use iter::Iterator;
|
use iter::Iterator;
|
||||||
use libc::{c_void, c_int};
|
use libc::{c_void, c_int};
|
||||||
use libc;
|
use libc;
|
||||||
|
use boxed::Box;
|
||||||
use ops::Drop;
|
use ops::Drop;
|
||||||
use option::{Some, None, Option};
|
use option::{Some, None, Option};
|
||||||
use os;
|
use os;
|
||||||
@@ -48,6 +50,7 @@ use slice::{AsSlice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice};
|
|||||||
use slice::CloneableVector;
|
use slice::CloneableVector;
|
||||||
use str::{Str, StrSlice, StrAllocating};
|
use str::{Str, StrSlice, StrAllocating};
|
||||||
use string::String;
|
use string::String;
|
||||||
|
use to_string::ToString;
|
||||||
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
|
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
@@ -1437,6 +1440,17 @@ impl fmt::Show for MapError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error for MapError {
|
||||||
|
fn description(&self) -> &str { "memory map error" }
|
||||||
|
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromError<MapError> for Box<Error> {
|
||||||
|
fn from_error(err: MapError) -> Box<Error> {
|
||||||
|
box err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl MemoryMap {
|
impl MemoryMap {
|
||||||
/// Create a new mapping with the given `options`, at least `min_len` bytes
|
/// Create a new mapping with the given `options`, at least `min_len` bytes
|
||||||
|
|||||||
Reference in New Issue
Block a user