Skip to content

Commit

Permalink
Rollup merge of #70904 - LukasKalbertodt:stabilize-seek-convenience, …
Browse files Browse the repository at this point in the history
…r=m-ou-se

Stabilize `Seek::stream_position` (feature `seek_convenience`)

Tracking issue: #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](#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.
  • Loading branch information
JohnTitor authored Jan 28, 2021
2 parents e32f372 + 8a18fb0 commit 025a850
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 0 additions & 1 deletion library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ impl<R: Seek> Seek for BufReader<R> {
/// # Example
///
/// ```no_run
/// #![feature(seek_convenience)]
/// use std::{
/// io::{self, BufRead, BufReader, Seek},
/// fs::File,
Expand Down
7 changes: 3 additions & 4 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ pub trait Seek {
/// # Example
///
/// ```no_run
/// #![feature(seek_convenience)]
/// #![feature(seek_stream_len)]
/// use std::{
/// io::{self, Seek},
/// fs::File,
Expand All @@ -1685,7 +1685,7 @@ pub trait Seek {
/// Ok(())
/// }
/// ```
#[unstable(feature = "seek_convenience", issue = "59359")]
#[unstable(feature = "seek_stream_len", issue = "59359")]
fn stream_len(&mut self) -> Result<u64> {
let old_pos = self.stream_position()?;
let len = self.seek(SeekFrom::End(0))?;
Expand All @@ -1706,7 +1706,6 @@ pub trait Seek {
/// # Example
///
/// ```no_run
/// #![feature(seek_convenience)]
/// use std::{
/// io::{self, BufRead, BufReader, Seek},
/// fs::File,
Expand All @@ -1723,7 +1722,7 @@ pub trait Seek {
/// Ok(())
/// }
/// ```
#[unstable(feature = "seek_convenience", issue = "59359")]
#[stable(feature = "seek_convenience", since = "1.51.0")]
fn stream_position(&mut self) -> Result<u64> {
self.seek(SeekFrom::Current(0))
}
Expand Down

0 comments on commit 025a850

Please sign in to comment.