From 111253c519adc17f5bbfa41b7368512ac7e1effd Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 14 Jul 2022 11:24:44 +1000 Subject: [PATCH] Rename `std::io::Error::try_downcast_inner` to `downcast` Signed-off-by: Jiahao XU --- library/std/src/io/error.rs | 8 ++++---- library/std/src/io/error/tests.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 4c6fd55ad13..8f2119425d1 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -808,7 +808,7 @@ pub fn into_inner(self) -> Option> { /// # Examples /// /// ``` - /// #![feature(io_error_try_downcast_inner)] + /// #![feature(io_error_downcast)] /// /// use std::fmt; /// use std::io; @@ -829,14 +829,14 @@ pub fn into_inner(self) -> Option> { /// /// impl From for E { /// fn from(err: io::Error) -> E { - /// err.try_downcast_inner::() + /// err.downcast::() /// .map(|b| *b) /// .unwrap_or_else(E::Io) /// } /// } /// ``` - #[unstable(feature = "io_error_try_downcast_inner", issue = "none")] - pub fn try_downcast_inner(self) -> result::Result, Self> + #[unstable(feature = "io_error_downcast", issue = "none")] + pub fn downcast(self) -> result::Result, Self> where E: error::Error + Send + Sync + 'static, { diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 558594c816e..c897a5e8701 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -154,32 +154,32 @@ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { impl error::Error for E {} #[test] -fn test_try_downcast_inner() { +fn test_std_io_error_downcast() { // Case 1: custom error, downcast succeeds let io_error = Error::new(ErrorKind::Other, Bojji(true)); - let e: Box = io_error.try_downcast_inner().unwrap(); + let e: Box = io_error.downcast().unwrap(); assert!(e.0); // Case 2: custom error, downcast fails let io_error = Error::new(ErrorKind::Other, Bojji(true)); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); // ensures that the custom error is intact assert_eq!(ErrorKind::Other, io_error.kind()); - let e: Box = io_error.try_downcast_inner().unwrap(); + let e: Box = io_error.downcast().unwrap(); assert!(e.0); // Case 3: os error let errno = 20; let io_error = Error::from_raw_os_error(errno); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(errno, io_error.raw_os_error().unwrap()); // Case 4: simple let kind = ErrorKind::OutOfMemory; let io_error: Error = kind.into(); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(kind, io_error.kind()); @@ -187,7 +187,7 @@ fn test_try_downcast_inner() { const SIMPLE_MESSAGE: SimpleMessage = SimpleMessage { kind: ErrorKind::Other, message: "simple message error test" }; let io_error = Error::from_static_message(&SIMPLE_MESSAGE); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind()); assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}"));