Skip to content

Commit 111253c

Browse files
committed
Rename std::io::Error::try_downcast_inner to downcast
Signed-off-by: Jiahao XU <[email protected]>
1 parent 516da4c commit 111253c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

library/std/src/io/error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ impl Error {
808808
/// # Examples
809809
///
810810
/// ```
811-
/// #![feature(io_error_try_downcast_inner)]
811+
/// #![feature(io_error_downcast)]
812812
///
813813
/// use std::fmt;
814814
/// use std::io;
@@ -829,14 +829,14 @@ impl Error {
829829
///
830830
/// impl From<io::Error> for E {
831831
/// fn from(err: io::Error) -> E {
832-
/// err.try_downcast_inner::<E>()
832+
/// err.downcast::<E>()
833833
/// .map(|b| *b)
834834
/// .unwrap_or_else(E::Io)
835835
/// }
836836
/// }
837837
/// ```
838-
#[unstable(feature = "io_error_try_downcast_inner", issue = "none")]
839-
pub fn try_downcast_inner<E>(self) -> result::Result<Box<E>, Self>
838+
#[unstable(feature = "io_error_downcast", issue = "none")]
839+
pub fn downcast<E>(self) -> result::Result<Box<E>, Self>
840840
where
841841
E: error::Error + Send + Sync + 'static,
842842
{

library/std/src/io/error/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -154,40 +154,40 @@ impl fmt::Display for E {
154154
impl error::Error for E {}
155155

156156
#[test]
157-
fn test_try_downcast_inner() {
157+
fn test_std_io_error_downcast() {
158158
// Case 1: custom error, downcast succeeds
159159
let io_error = Error::new(ErrorKind::Other, Bojji(true));
160-
let e: Box<Bojji> = io_error.try_downcast_inner().unwrap();
160+
let e: Box<Bojji> = io_error.downcast().unwrap();
161161
assert!(e.0);
162162

163163
// Case 2: custom error, downcast fails
164164
let io_error = Error::new(ErrorKind::Other, Bojji(true));
165-
let io_error = io_error.try_downcast_inner::<E>().unwrap_err();
165+
let io_error = io_error.downcast::<E>().unwrap_err();
166166

167167
// ensures that the custom error is intact
168168
assert_eq!(ErrorKind::Other, io_error.kind());
169-
let e: Box<Bojji> = io_error.try_downcast_inner().unwrap();
169+
let e: Box<Bojji> = io_error.downcast().unwrap();
170170
assert!(e.0);
171171

172172
// Case 3: os error
173173
let errno = 20;
174174
let io_error = Error::from_raw_os_error(errno);
175-
let io_error = io_error.try_downcast_inner::<E>().unwrap_err();
175+
let io_error = io_error.downcast::<E>().unwrap_err();
176176

177177
assert_eq!(errno, io_error.raw_os_error().unwrap());
178178

179179
// Case 4: simple
180180
let kind = ErrorKind::OutOfMemory;
181181
let io_error: Error = kind.into();
182-
let io_error = io_error.try_downcast_inner::<E>().unwrap_err();
182+
let io_error = io_error.downcast::<E>().unwrap_err();
183183

184184
assert_eq!(kind, io_error.kind());
185185

186186
// Case 5: simple message
187187
const SIMPLE_MESSAGE: SimpleMessage =
188188
SimpleMessage { kind: ErrorKind::Other, message: "simple message error test" };
189189
let io_error = Error::from_static_message(&SIMPLE_MESSAGE);
190-
let io_error = io_error.try_downcast_inner::<E>().unwrap_err();
190+
let io_error = io_error.downcast::<E>().unwrap_err();
191191

192192
assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind());
193193
assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}"));

0 commit comments

Comments
 (0)