Tracking Issue for io_error_downcast
· Issue #99262 · rust-lang/rust (original) (raw)
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 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_inner to std::io::Error libs-team#57
- Implementation: Add new unstable API downcast to std::io::Error #98387
- Update
std::io::Error::downcast
return type and doc: Update std::io::Error::downcast return type #120117 - Final comment period (FCP)1
- Stabilization PR Stablise io_error_downcast #124076
Unresolved Questions
- None yet.