-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for owned locked stdio handles #86845
Comments
…riplett stdio_locked: add tracking issue Add the tracking issue number rust-lang#86845 to the stability attributes for the implementation in rust-lang#86799. r? `@joshtriplett` `@rustbot` label +A-io +C-cleanup +T-libs-api
Instead of adding |
I think when I brought up this possibility a while ago, there were objections that doing so would preclude certain future changes to the API. |
This method has been around for a while, and it seems reasonable. I think it'd be appropriate to consider stabilizing it. @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Would someone be able to dig up a link to this discussion? It seems like a better solution than introducing many new functions as long as the team is now willing to commit to the required API constraints. @rfcbot concern can |
Would we still want these new APIs if |
I found the "just make |
As far as I can tell, #15023 mentions that such a change would to some extent be a breaking change. |
I can try to locate the discussion; it might have been a Zulip thread or two. It was also a while ago (May or June 2021?), so it might take substantial digging. |
@dtolnay I think I found it, though it kind of meanders. I personally don't agree that it's worth it to maintain future implementation flexibility (to a hypothetical design similar to one that was already rejected) at the cost of making things more difficult for beginners. |
Even if |
@joshtriplett proposal cancelled. |
Make regular stdio lock() return 'static handles This also deletes the unstable API surface area previously added to expose this functionality on new methods rather than built into the current set. Closes rust-lang#86845 (tracking issue for unstable API needed without this) r? ````@dtolnay```` to kick off T-libs-api FCP
Feature gate:
#![feature(stdio_locked)]
This is a tracking issue for adding owned locked handles to stdio.
Especially for beginners, using stdio handles can involve intimidating problems with locking and lifetimes. First, the user has to call a free function (
stderr()
,stdin()
,stdout()
) to get a handle on the stream; then, the user might have to call thelock()
method (for example, to gain access to thelines()
iterator constructor). At this point, lifetime issues rapidly arise: the following code (playground) will produce a compile error.The need to create a
let
binding to the handle seems confusing and frustrating, especially if the program does not need to use the handle again. The explanation is that the lock behaves as if it borrows the original handle fromstdin()
, and the temporary value created for the call to thelock()
method is dropped at the end of the statement, invalidating the borrow. That explanation might be beyond the current level of understanding of a beginner who simply wants to write an interactive terminal program.Even experienced Rust programmers sometimes have trouble with the lifetime management required for using locked stdio handles: (comment), (comment).
Fortunately, the stdio handles don't contain any non-static references, so it's possible to create owned locks such as
StdinLock<'static>
. This proposal creates methods and free functions for creating owned locked stdio handles. The methods consumeself
, eliminating any lifetime problems. The free functions directly return an owned locked handle, for programs where there is no need to use an unlocked handle. The implementation currently depends on the mutex references in the stdio handles being static, but this does not preclude future changes to the locking internals (for example, usingArc
to wrap the mutex).Public API
Steps / History
Unresolved Questions
stdin_locked()
, etc.) over the ones that obtain unlocked handles (stdin()
, etc.)?@rustbot label +A-io +D-newcomer-roadblock
The text was updated successfully, but these errors were encountered: