@@ -129,9 +129,7 @@ impl Error {
129
129
///
130
130
/// This function is used to generically create I/O errors which do not
131
131
/// originate from the OS itself. The `error` argument is an arbitrary
132
- /// payload which will be contained in this `Error`. Accessors as well as
133
- /// downcasting will soon be added to this type as well to access the custom
134
- /// information.
132
+ /// payload which will be contained in this `Error`.
135
133
///
136
134
/// # Examples
137
135
///
@@ -174,8 +172,9 @@ impl Error {
174
172
175
173
/// Returns the OS error that this error represents (if any).
176
174
///
177
- /// If this `Error` was constructed via `last_os_error` then this function
178
- /// will return `Some`, otherwise it will return `None`.
175
+ /// If this `Error` was constructed via `last_os_error` or
176
+ /// `from_raw_os_error`, then this function will return `Some`, otherwise
177
+ /// it will return `None`.
179
178
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
180
179
pub fn raw_os_error ( & self ) -> Option < i32 > {
181
180
match self . repr {
@@ -184,6 +183,43 @@ impl Error {
184
183
}
185
184
}
186
185
186
+ /// Returns a reference to the inner error wrapped by this error (if any).
187
+ ///
188
+ /// If this `Error` was constructed via `new` then this function will
189
+ /// return `Some`, otherwise it will return `None`.
190
+ #[ unstable( feature = "io_error_inner" , reason = "recently added" ) ]
191
+ pub fn get_ref ( & self ) -> Option < & ( error:: Error +Send +Sync ) > {
192
+ match self . repr {
193
+ Repr :: Os ( ..) => None ,
194
+ Repr :: Custom ( ref c) => Some ( & * c. error ) ,
195
+ }
196
+ }
197
+
198
+ /// Returns a mutable reference to the inner error wrapped by this error
199
+ /// (if any).
200
+ ///
201
+ /// If this `Error` was constructed via `new` then this function will
202
+ /// return `Some`, otherwise it will return `None`.
203
+ #[ unstable( feature = "io_error_inner" , reason = "recently added" ) ]
204
+ pub fn get_mut ( & mut self ) -> Option < & mut ( error:: Error +Send +Sync ) > {
205
+ match self . repr {
206
+ Repr :: Os ( ..) => None ,
207
+ Repr :: Custom ( ref mut c) => Some ( & mut * c. error ) ,
208
+ }
209
+ }
210
+
211
+ /// Consumes the `Error`, returning its inner error (if any).
212
+ ///
213
+ /// If this `Error` was constructed via `new` then this function will
214
+ /// return `Some`, otherwise it will return `None`.
215
+ #[ unstable( feature = "io_error_inner" , reason = "recently added" ) ]
216
+ pub fn into_inner ( self ) -> Option < Box < error:: Error +Send +Sync > > {
217
+ match self . repr {
218
+ Repr :: Os ( ..) => None ,
219
+ Repr :: Custom ( c) => Some ( c. error )
220
+ }
221
+ }
222
+
187
223
/// Returns the corresponding `ErrorKind` for this error.
188
224
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
189
225
pub fn kind ( & self ) -> ErrorKind {
@@ -216,7 +252,7 @@ impl error::Error for Error {
216
252
}
217
253
}
218
254
219
- fn cause ( & self ) -> Option < & Error > {
255
+ fn cause ( & self ) -> Option < & error :: Error > {
220
256
match self . repr {
221
257
Repr :: Os ( ..) => None ,
222
258
Repr :: Custom ( ref c) => c. error . cause ( ) ,
0 commit comments