-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add provided methods Seek::{stream_len, stream_position}
#58422
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
c2f43a1
to
2440db0
Compare
Seems plausible to me! Since this is changing a pretty core trait, even though these functions are unstable, I'd want to gain some other feedback too: @rfcbot fcp merge |
Team member @alexcrichton 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. |
@rfcbot concern position |
Could @rfcbot concern len |
I would be fine with changing both names! The only (very minor) argument against |
This len would return a result, which should indicate that there's something bigger going on. |
2440db0
to
2dfac80
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The ICE will be fixed once a new beta is cut that includes #58501, but the bigger issue is that |
Interesting! I just pushed the renaming changes ( First I was confused, but then I remembered this question of dtolnay's Rust quiz. Here is a minimal example on Playground. So: keep |
FWIW I also think that having a method |
Oh man, that quiz question. I think that rules out I am mildly opposed to I think we can land this with any name other than |
We can reconsider |
Is that really the case, though? RFC 1105 defines what changes are considered "major" and which ones are considered "minor". It says:
The RFC uses a different example to show that adding a defaulted item can be a breaking change, but I guess the reasoning still applies. Now of course we wouldn't want to have a change that we know causes real breakage in the world -- regardless if it's minor or major according to the RFC. So I guess what I'm asking is: do you consider this one breakage in the compiler suite as enough evidence that such a change is not OK? Or would it be better to have a crater run? As @jonas-schievink pointed out in a private chat with me, the code that breaks in Travis is extremely fishy: neither
That's not necessarily true, right? Someone could implement I don't like the |
☔ The latest upstream changes (presumably #58208) made this pull request unmergeable. Please resolve the merge conflicts. |
These two methods are defined in terms of `Seek::seek` and are added for convenience. Tests are included.
2dfac80
to
e8ee00a
Compare
Seek::{stream_len, current_position}
Seek::{stream_len, stream_position}
I renamed the methods again to: |
But then you have to sync the metadata first, which can be more expensive than two seeks (see Stackoverflow) |
a481512
to
c518f2d
Compare
Is that accurate? I thought However, I did find another possible reason to prefer seeking, even on files: files in |
Fix typos in the documentation Co-Authored-By: LukasKalbertodt <lukas.kalbertodt@gmail.com>
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
@bors: r+ |
📌 Commit f95219f has been approved by |
Add provided methods `Seek::{stream_len, stream_position}` This adds two new, provided methods to the `io::Seek` trait: - `fn stream_len(&mut self) -> Result<u64>` - `fn stream_position(&mut self) -> Result<u64>` Both are added for convenience and to improve readability in user code. Reading `file.stream_len()` is much better than to manually seek two or three times. Similarly, `file.stream_position()` is much more clear than `file.seek(SeekFrom::Current(0))`. You can find prior discussions [in this internals thread](https://internals.rust-lang.org/t/pre-rfc-idea-extend-io-seek-with-convenience-methods-with-e-g-stream-len/9262). I think I addressed all concerns in that thread. I already wrote three RFCs to add a small new API to libstd but I noticed that many public changes to libstd happen without an RFC. So I figured I can try opening a PR directly without going through RFCs first. After all, we do have rfcbot here too. If you think this change is too big to merge without an RFC, I can still close this PR and write an RFC.
☀️ Test successful - checks-travis, status-appveyor |
/// Ok(()) | ||
/// } | ||
/// ``` | ||
#[unstable(feature = "seek_convenience", issue = "0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't have tracking issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tracking issue number for `seek_convenience` We forgot to do that in rust-lang#58422
Add tracking issue number for `seek_convenience` We forgot to do that in rust-lang#58422
Edit: Tracking issue
This adds two new, provided methods to the
io::Seek
trait:fn stream_len(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Both are added for convenience and to improve readability in user code. Reading
file.stream_len()
is much better than to manually seek two or three times. Similarly,file.stream_position()
is much more clear thanfile.seek(SeekFrom::Current(0))
.You can find prior discussions in this internals thread. I think I addressed all concerns in that thread.
I already wrote three RFCs to add a small new API to libstd but I noticed that many public changes to libstd happen without an RFC. So I figured I can try opening a PR directly without going through RFCs first. After all, we do have rfcbot here too. If you think this change is too big to merge without an RFC, I can still close this PR and write an RFC.