-
Notifications
You must be signed in to change notification settings - Fork 20
stdio set
, close
and take
methods
#500
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
Comments
|
@the8472 Thanks for writing this! |
Would this feature also allow third-party test frameworks to capture std{out,err} like the built-in test framework? |
What the builtin framework uses are a per-thread overrides for |
What should |
So println will then do the same as if the process had been started with that setup. |
We discussed this in the libs-api meeting and we're happy to accept this. In the meeting we proposed some extensions to the API so that the full |
Proposal
Problem statement
Currently it's not possible to replace, close or take exclusive ownership of stdio handles without using platform-specific crates such as libc, rustix or windows-sys.
Motivating examples or use cases
A program that
File
type, and eventually wants to close itGenerally stdio handles are considered shared resources. Being able to make them exclusive instead early during program startup can be important for robustness and correctness.
Solution sketch
The following only lists
Stdout
but would equally apply to theStderr
,Stdin
and the*Lock
types.take_file
,replace_file
andclose
are convenience APIs that can be built on top ofas_fd().try_clone_to_owned()
+set()
Open questions
take_file()
?/dev/null
orNUL
handle when has been closed before?StdioFile
instead ofFile
?Alternatives
#[cfg]
directivesLinks and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: