nix: No conversion between Errno and std::io::Error/i32
There are situation where you want to have the raw error value of an error, e.g. for passing back into C code. Also, there is already a perfectly good type for holding errno in Rust, std::io::Error
. It does support getting the raw error value. I suggest deprecating Errno
in favor of std::io::Error
or at least adding the necessary conversions.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
Here’s a related issue that doesn’t work right now
Also, I’d like to make a case for why that impl should be added again:
nix::Error
is basically a subset ofio::Error
. Whileio::Error
can hold an arbitrary user error of any ErrorKind or an errno,nix::Error
can hold a user error of kindUnsupportedOperation, InvalidPath, InvalidUtf8
or an errno. IMO there’s a very clear mapping between the latter and the former, and I don’t think it makes sense to have to make a custom error type just because you have code that does both stdlib io and unix-specific io. Obviously it’s a good idea to havenix::Error
as its own separate type, since it vastly reduces the set of errors that can exist and it makes it much easier to handle, but if you do need to “widen” the error type, I think converting toio::Error
makes more sense than having anenum Error { Nix(nix::Error), Io(io::Error) }