Skip to content

Tracking Issue for io_error_downcast #99262

Closed

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

Unresolved Questions

  • None yet.

Footnotes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: A tracking issue for an RFC or an unstable feature.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions