-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
Feature gate: #![feature(io_error_downcast)]
This is a tracking issue for new API std::io::Error::downcast.
Existing APIs requires two separate calls to obtain the raw os error or the inner error and they both return Option.
Thus, users would have to first call Error::get_ref to check that we indeed has an inner error and checked that it is the type we expected.
Users cannot use std::io::Error::into_inner becuase takes the error by value and returns Option<Box<dyn Error + Send + Sync>> instead of Result<Box<dyn Error + Send + Sync>, Self>.
They also cannot workaround this issue by calling Error::raw_os_error, since the io::Error can also be constructed using impl From<ErrorKind> for Error or using other internal methods only accessible by the std library.
This new feature io_error_downcast solved this issue by providing new API std::io::Error::downcast to downcast the inner error easily without unwrap or expect.
Public API
// std::io::Error
impl Error {
fn downcast<E: std::error::Error + Send + Sync + 'static>(self) -> Result<E, Self>;
}Steps / History
- API Change Proposal: Add new API
try_downcast_innertostd::io::Errorlibs-team#57 - Implementation: Add new unstable API
downcasttostd::io::Error#98387 - Update
std::io::Error::downcastreturn type and doc: Updatestd::io::Error::downcastreturn type #120117 - Final comment period (FCP)1
- Stabilization PR Stablise io_error_downcast #124076
Unresolved Questions
- None yet.