Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd provided methods `Seek::{stream_len, stream_position}` #58422
Conversation
rust-highfive
assigned
alexcrichton
Feb 13, 2019
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Feb 13, 2019
This comment has been minimized.
This comment has been minimized.
|
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 |
LukasKalbertodt
force-pushed the
LukasKalbertodt:seek-convenience
branch
from
c2f43a1
to
2440db0
Feb 13, 2019
shepmaster
added
C-enhancement
T-libs
labels
Feb 13, 2019
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 14, 2019
•
|
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
added
proposed-final-comment-period
disposition-merge
labels
Feb 14, 2019
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern position |
This comment has been minimized.
This comment has been minimized.
|
Could @rfcbot concern len |
This comment has been minimized.
This comment has been minimized.
|
I would be fine with changing both names! The only (very minor) argument against |
This comment has been minimized.
This comment has been minimized.
|
This len would return a result, which should indicate that there's something bigger going on. |
LukasKalbertodt
force-pushed the
LukasKalbertodt:seek-convenience
branch
from
2440db0
to
2dfac80
Feb 17, 2019
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
The ICE will be fixed once a new beta is cut that includes #58501, but the bigger issue is that |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
FWIW I also think that having a method |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
We can reconsider |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
|
|
LukasKalbertodt
force-pushed the
LukasKalbertodt:seek-convenience
branch
from
2dfac80
to
e8ee00a
Mar 10, 2019
LukasKalbertodt
changed the title
Add provided methods `Seek::{stream_len, current_position}`
Add provided methods `Seek::{stream_len, stream_position}`
Mar 10, 2019
This comment has been minimized.
This comment has been minimized.
|
I renamed the methods again to: |
This comment has been minimized.
This comment has been minimized.
rfcbot
added
the
final-comment-period
label
Mar 11, 2019
This comment has been minimized.
This comment has been minimized.
Dr-Emann
commented
Mar 13, 2019
|
Are we also allowed to do something like let current = cursor.seek(SeekFrom::Current(0))?;
let end = cursor.seek(SeekFrom::End(0))?;
if (current != end) {
cursor.seek(SeekFrom::Start(current))?;
}To prevent the third call to seek if we are at the end already? |
jonas-schievink
added
relnotes
and removed
relnotes
labels
Mar 13, 2019
This comment has been minimized.
This comment has been minimized.
But then you have to sync the metadata first, which can be more expensive than two seeks (see Stackoverflow) |
hellow554
reviewed
Mar 14, 2019
src/libstd/io/mod.rs Outdated
hellow554
reviewed
Mar 14, 2019
src/libstd/io/mod.rs Outdated
LukasKalbertodt
added some commits
Mar 14, 2019
LukasKalbertodt
force-pushed the
LukasKalbertodt:seek-convenience
branch
from
a481512
to
c518f2d
Mar 14, 2019
This comment has been minimized.
This comment has been minimized.
Dr-Emann
commented
Mar 14, 2019
Is that accurate? I thought However, I did find another possible reason to prefer seeking, even on files: files in |
tbu-
reviewed
Mar 17, 2019
src/libstd/io/mod.rs Outdated
src/libstd/io/mod.rs Outdated
rfcbot
added
the
finished-final-comment-period
label
Mar 21, 2019
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 21, 2019
|
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. |
rfcbot
removed
the
final-comment-period
label
Mar 21, 2019
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Mar 21, 2019
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 21, 2019
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
the
merged-by-bors
label
Mar 21, 2019
bors
merged commit f95219f
into
rust-lang:master
Mar 21, 2019
1 check passed
lzutao
reviewed
Mar 22, 2019
| /// Ok(()) | ||
| /// } | ||
| /// ``` | ||
| #[unstable(feature = "seek_convenience", issue = "0")] |
LukasKalbertodt commentedFeb 13, 2019
•
edited
Edit: Tracking issue
This adds two new, provided methods to the
io::Seektrait: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.