diff options
| author | Steven Fackler <sfackler@gmail.com> | 2015-05-26 21:06:56 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2015-05-27 21:53:54 -0700 |
| commit | b529a7837bcbaee4a5e9f61ee659c94af7e41f60 (patch) | |
| tree | 34f1dfe36ba26d7ab633c0ce1a0dacf366d97a44 /src/libstd/io/error.rs | |
| parent | 4458b5a9d5f11af5cfeb2201a4065131baeeec36 (diff) | |
| download | rust-b529a7837bcbaee4a5e9f61ee659c94af7e41f60.tar.gz rust-b529a7837bcbaee4a5e9f61ee659c94af7e41f60.zip | |
Add accessors for io::Error's inner error.
error::Error itself has downcasting methods, so there's no need to duplicate those here.
Diffstat (limited to 'src/libstd/io/error.rs')
| -rw-r--r-- | src/libstd/io/error.rs | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 70e6d7eb265..c3a773617e0 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -129,9 +129,7 @@ impl Error { /// /// This function is used to generically create I/O errors which do not /// originate from the OS itself. The `error` argument is an arbitrary - /// payload which will be contained in this `Error`. Accessors as well as - /// downcasting will soon be added to this type as well to access the custom - /// information. + /// payload which will be contained in this `Error`. /// /// # Examples /// @@ -174,8 +172,9 @@ impl Error { /// Returns the OS error that this error represents (if any). /// - /// If this `Error` was constructed via `last_os_error` then this function - /// will return `Some`, otherwise it will return `None`. + /// If this `Error` was constructed via `last_os_error` or + /// `from_raw_os_error`, then this function will return `Some`, otherwise + /// it will return `None`. #[stable(feature = "rust1", since = "1.0.0")] pub fn raw_os_error(&self) -> Option<i32> { match self.repr { @@ -184,6 +183,43 @@ impl Error { } } + /// Returns a reference to the inner error wrapped by this error (if any). + /// + /// If this `Error` was constructed via `new` then this function will + /// return `Some`, otherwise it will return `None`. + #[unstable(feature = "io_error_inner", reason = "recently added")] + pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync)> { + match self.repr { + Repr::Os(..) => None, + Repr::Custom(ref c) => Some(&*c.error), + } + } + + /// Returns a mutable reference to the inner error wrapped by this error + /// (if any). + /// + /// If this `Error` was constructed via `new` then this function will + /// return `Some`, otherwise it will return `None`. + #[unstable(feature = "io_error_inner", reason = "recently added")] + pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync)> { + match self.repr { + Repr::Os(..) => None, + Repr::Custom(ref mut c) => Some(&mut *c.error), + } + } + + /// Consumes the `Error`, returning its inner error (if any). + /// + /// If this `Error` was constructed via `new` then this function will + /// return `Some`, otherwise it will return `None`. + #[unstable(feature = "io_error_inner", reason = "recently added")] + pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> { + match self.repr { + Repr::Os(..) => None, + Repr::Custom(c) => Some(c.error) + } + } + /// Returns the corresponding `ErrorKind` for this error. #[stable(feature = "rust1", since = "1.0.0")] pub fn kind(&self) -> ErrorKind { @@ -216,7 +252,7 @@ impl error::Error for Error { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&error::Error> { match self.repr { Repr::Os(..) => None, Repr::Custom(ref c) => c.error.cause(), |
