diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-26 21:00:43 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-04 15:59:30 -0800 |
| commit | 95d904625b4d45af80b4e40d51a3a0fde1abaa8a (patch) | |
| tree | b0872e63b8d75543ce5141ceba44c12c459474f2 /src/rustbook/error.rs | |
| parent | 3b3bb0e682c2d252e9f62dd9df5cff9552af91ad (diff) | |
| download | rust-95d904625b4d45af80b4e40d51a3a0fde1abaa8a.tar.gz rust-95d904625b4d45af80b4e40d51a3a0fde1abaa8a.zip | |
std: Deprecate std::old_io::fs
This commit deprecates the majority of std::old_io::fs in favor of std::fs and its new functionality. Some functions remain non-deprecated but are now behind a feature gate called `old_fs`. These functions will be deprecated once suitable replacements have been implemented. The compiler has been migrated to new `std::fs` and `std::path` APIs where appropriate as part of this change.
Diffstat (limited to 'src/rustbook/error.rs')
| -rw-r--r-- | src/rustbook/error.rs | 68 |
1 files changed, 10 insertions, 58 deletions
diff --git a/src/rustbook/error.rs b/src/rustbook/error.rs index 43c882c7d5b..294b4e55669 100644 --- a/src/rustbook/error.rs +++ b/src/rustbook/error.rs @@ -10,10 +10,8 @@ //! Error handling utilities. WIP. +use std::error::Error; use std::fmt; -use std::fmt::{Debug, Formatter}; - -use std::old_io::IoError; pub type CliError = Box<Error + 'static>; pub type CliResult<T> = Result<T, CliError>; @@ -21,63 +19,17 @@ pub type CliResult<T> = Result<T, CliError>; pub type CommandError = Box<Error + 'static>; pub type CommandResult<T> = Result<T, CommandError>; -pub trait Error { - fn description(&self) -> &str; - - fn detail(&self) -> Option<&str> { None } - fn cause(&self) -> Option<&Error> { None } -} - -pub trait FromError<E> { - fn from_err(err: E) -> Self; -} - -impl Debug for Box<Error + 'static> { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{}", self.description()) - } -} - -impl<E: Error + 'static> FromError<E> for Box<Error + 'static> { - fn from_err(err: E) -> Box<Error + 'static> { - box err as Box<Error> - } -} +pub fn err(s: &str) -> CliError { + struct E(String); -impl<'a> Error for &'a str { - fn description<'b>(&'b self) -> &'b str { - *self + impl Error for E { + fn description(&self) -> &str { &self.0 } } -} - -impl Error for String { - fn description<'a>(&'a self) -> &'a str { - &self[..] + impl fmt::Display for E { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } } -} - -impl<'a> Error for Box<Error + 'a> { - fn description(&self) -> &str { (**self).description() } - fn detail(&self) -> Option<&str> { (**self).detail() } - fn cause(&self) -> Option<&Error> { (**self).cause() } -} - -impl FromError<()> for () { - fn from_err(_: ()) -> () { () } -} -impl FromError<IoError> for IoError { - fn from_err(error: IoError) -> IoError { error } + Box::new(E(s.to_string())) } - -impl Error for IoError { - fn description(&self) -> &str { - self.desc - } - fn detail(&self) -> Option<&str> { - self.detail.as_ref().map(|s| &s[..]) - } -} - - -//fn iter_map_err<T, U, E, I: Iterator<Result<T,E>>>(iter: I, |
