Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other variants to std::io::ErrorKind enum #64314

Open
Alphare opened this issue Sep 9, 2019 · 6 comments
Open

Add other variants to std::io::ErrorKind enum #64314

Alphare opened this issue Sep 9, 2019 · 6 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Alphare
Copy link

Alphare commented Sep 9, 2019

I was trying to rewrite Python code in Rust and I need to match against what could be NotADirectory (ENOTDIR) and saw that ErrorKind's variants do not include many errnos present in libc - to speak only of the Unix platform - including the one I need.

Is there a reason why those variants were not implemented? Could this be my first contribution to Rust?

@Mark-Simulacrum
Copy link
Member

The docs do say "This list is intended to grow over time and it is not recommended to exhaustively match against it." currently (and we enforce non exhaustive matching via an attribute); I think our hands technically aren't tied here but we'll want to be very cautious.

@rust-lang/libs -- does anyone have thoughts on growing io::ErrorKind to have more variants? I don't recall us doing so in the last several years...

To address your specific concern, you can use raw_os_error() on io::Error and compare with libc's ENOTDIR as needed.

@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 10, 2019
@alexcrichton
Copy link
Member

I agree that it's been so long since we've added one that we should probably do so carefully (aka use crater) but I think in general it's fine to add more.

@SimonSapin
Copy link
Contributor

The enum has #[non_exhaustive] so I’m not too worried a priori.

@Alphare
Copy link
Author

Alphare commented Sep 11, 2019

Is this something I can reasonably tackle as a first contribution?

@Alphare Alphare changed the title Add other variants to ErrorKind enum Add other variants to std::io::ErrorKind enum Sep 11, 2019
@SimonSapin
Copy link
Contributor

Add variants sounds fine, but when would NotADirectory be returned? If it’s in existing APIs, what do they return today?

@Alphare
Copy link
Author

Alphare commented Sep 11, 2019

@SimonSapin I think one case where it can happen is when you try a filesystem operation on a/b where a is not a directory. As of now it falls into the Other variant, but the match clause should translate this constant into NotADirectory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants