diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-10-03 14:24:49 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-11-02 15:31:52 -0800 |
| commit | 7c152f870da62348ec5a0d9104c20db69910a415 (patch) | |
| tree | 226afdcba9a46822fe952e62cb12e7e5702326b5 /src/libstd | |
| parent | 6815c2e8e8dae3d8dedfe95e985a79c57841bdb2 (diff) | |
| download | rust-7c152f870da62348ec5a0d9104c20db69910a415.tar.gz rust-7c152f870da62348ec5a0d9104c20db69910a415.zip | |
Add Error impls to a few key error types
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/mod.rs | 18 | ||||
| -rw-r--r-- | src/libstd/os.rs | 14 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c6f237ff1da..3dcd8d792a4 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -222,7 +222,9 @@ responding to errors that may occur while attempting to read the numbers. #![deny(unused_must_use)] use char::Char; +use clone::Clone; use default::Default; +use error::{FromError, Error}; use fmt; use int; 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. #[deriving(PartialEq, Eq, Clone, Show)] pub enum IoErrorKind { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 5b3c872d2b7..9846f7b653e 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -32,11 +32,13 @@ #![allow(non_snake_case)] use clone::Clone; +use error::{FromError, Error}; use fmt; use io::{IoResult, IoError}; use iter::Iterator; use libc::{c_void, c_int}; use libc; +use boxed::Box; use ops::Drop; use option::{Some, None, Option}; use os; @@ -48,6 +50,7 @@ use slice::{AsSlice, ImmutableSlice, MutableSlice, ImmutablePartialEqSlice}; use slice::CloneableVector; use str::{Str, StrSlice, StrAllocating}; use string::String; +use to_string::ToString; use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; 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)] impl MemoryMap { /// Create a new mapping with the given `options`, at least `min_len` bytes |
