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

Unresolved Questions

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html