-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Should getting a BorrowedHandle from Stdin, Stdout or Stderr return a Result on Windows? #90964
Copy link
Copy link
Closed
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
On Windows, the standard library's function for getting a stdio handle looks like this:
Note that it only returns a handle if one is set, otherwise it returns an error.
In contrast, the public
AsRawHandlestdio implementation ignores errors returned byGetStdHandleand just uses the returned value, whatever that may be.The Safe I/O RFC introduced new types for managing handles. The
AsHandletrait is intended to be a drop in replacement for the oldAsRawHandletrait but returns aBorrowedHandleinstead of aRawHandle.I personally don't think
AsHandleshould be implemented for stdio types. Instead a function with a signature similar to this should be implemented:It would work similarly to the internal
get_handlefunction in that it will return an error if there is no handle to return.Reasons for a
try_as_handle()function instead of implementingAsHandleon stdio types:BorrowedHandleshould be what the name implies: a borrow of a handle. It should not be an error sentinel value (which may overlap with an actual handle value).Reasons not to do this:
INVALID_HANDLE_VALUEwill probably lead to an error in any case so it's unclear how much of an issue this is in practice.AsRawHandleandAsHandlearen't implemented for all the same types.See also: I/O Safety Tracking Issue (#87074) and a previous discussion on internals.