-
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
Tracking issue for Seek::{stream_len, stream_position} (feature seek_convenience
)
#59359
Comments
`reader.stream_pos()` is equivalent to `reader.seek(SeekFrom::Current(0))`. See <rust-lang/rust#59359>.
`reader.stream_position()` is equivalent to `reader.seek(SeekFrom::Current(0))`. See <rust-lang/rust#59359>.
`reader.stream_position()` is equivalent to `reader.seek(SeekFrom::Current(0))`. See <rust-lang/rust#59359>.
`reader.stream_position()` is equivalent to `reader.seek(SeekFrom::Current(0))`. See <rust-lang/rust#59359>.
As the issue calls for a bikeshed... |
From the API user perspective, |
I opened a stabilization PR here: #70904
@marmistrz Yes, that would be nice. But it's not possible as the method is just a small helper around |
Yes, therefore this should be implemented separately, on the low level, just as it's done in yanix: |
@marmistrz Unfortunately, I don't quite understand what you are suggesting. And in particular: are you opposing stabilization of the features as they currently are? |
In my opinion, instead of the cross-platform implementation present in I think that the API should not be stabilized, because it's semantically incorrect to require mutable borrows for immutable queries. If the API user only has an immutable reference, they'll still have to use platform-specific unsafe code. (casting |
A few things:
|
@LukasKalbertodt " |
|
I think for files there could be a specialized |
@marmistrz As with most io-traits there is the |
…enience, r=m-ou-se Stabilize `Seek::stream_position` (feature `seek_convenience`) Tracking issue: rust-lang#59359 Unresolved questions from tracking issue: - "Override `stream_len` for `File`?" → we can do that in the future, this does not block stabilization. - "Rename to `len` and `position`?" → as noted in the tracking issue, both of these shorter names have problems (`len` is usually a cheap getter, `position` clashes with `Cursor`). I do think the current names are perfectly fine. - "Rename `stream_position` to `tell`?" → as mentioned in [the comment bringing this up](rust-lang#59359 (comment)), `stream_position` is more descriptive. I don't think `tell` would be a good name. What remains to decide, is whether or not adding these methods is worth it.
`reader.stream_position()` is equivalent to `reader.seek(SeekFrom::Current(0))`. See <rust-lang/rust#59359>.
For BufWriter, it might not be clear to users that this method will write out the buffer. Even though that shouldn't be a big problem (and possible to deduct). Same with |
This tracking issue is almost 3 years old. @LukasKalbertodt any progress on stabilization? |
@hellow554 Nope, I'm not really involved in this anymore. I am certainly not working on any stabilization attempts. Sorry! |
I would like to stablize this feature. @m-ou-se can you please start a fcp merge request? I would open a PR to stablize the feature once a decision has been made. |
@hellow554 there were a bunch of concerns raised about
|
Is there any sign of progress on this? |
The next step would probably be to move the functions into a separate trait, as suggested by: #70904 (comment) . I'm not sure if one trait would be better, or it should be two traits. IDK. |
It seems a bit silly to require a separate trait for that, in my opinion. As the length of a stream can always be found by three seek operations, that can always be a sane default, and the default behavior can be overridden by e.g. |
I agree that there is more overhead, but read the comment right above the one I linked (this one #70904 (comment)). Having a separate trait allows us to bring the API to more types, also ones that don't impl Seek, like for example slices. I suppose they prioritize that advantage to be more important than the additional overhead, shrug. |
Not sure this is the right place to ask this but it regards the Seek trait: Currently the fn stream_position(&mut self) -> Result<u64> That means it needs a mutable reference and it is fallible. I was looking around the For example: When streaming from a simple file (think std::fs::File -> std::io::BufReader -> flate2 -> ...), the common way to monitor progress on the underlying file seems to be mutably cloning the initial The pub fn position(&self) -> u64
Was wondering if it wouldn't be best to move it into the Alternatively: it could be implemented for the |
Imagine a file-like object permitting seekable access to a streaming network resource that may or may not know its length in advance, by downloading into a buffer (either in-memory or on-disk) and, whenever the calling code tries to read past the end of the buffer, blocks until more data is available from the network. In the case the network server doesn't send a length, the only way for this object to compute its length (or indeed to seek relative to EOF at all) is to wait for the entire network resource to be downloaded into its buffer. If every object that implemented @fedy-cz I'll also point out that |
The semantic of
I think About the tracking: I also think that renaming |
This is a tracking issue for
Seek::{stream_len, stream_position}
. Proposed and implemented in #58422.Unresolved questions:
stream_len
forFile
? (is metadata syncing a problem? comment a, comment b)len
andposition
? (but that's a strange signature forlen
andposition
clashes withCursor
The text was updated successfully, but these errors were encountered: