Skip to content

Add type alias for raw OS errors #173

Closed
@joboet

Description

@joboet

Proposal

Problem statement

io::Error assumes OS error values always fit into an i32, but that is not true for all platforms.

Motivation, use-cases

rust-lang/rust#105861 introduces std support for UEFI applications. There is however a problem with the way native OS errors are handled in std, as the current API expects error values to fit into an i32. While this the case for all currently supported platforms, UEFI diverges from the pattern by using an usize1 as error type. This forces code supporting UEFI to convert the native errors to custom io::Errors, which does not fit well with the current API and looses information.

Solution sketches

Add a new type alias to std::io (naming open to bikeshedding):

pub type RawOsError = /* platform error type, `i32` most of the time */;

and use it in place of i32 in io::Error::from_raw_os_error and io::Error::raw_os_error. This is a backwards-compatible change on all current platforms, but new code wishing to support platforms like UEFI will need to use the new error type to ensure portability.

CC @Ayush1325

Footnotes

  1. At least according to the specification. However, error values always have the highest bit set, so isize would be more convenient...

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions