File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -492,6 +492,16 @@ impl<R: ?Sized + Seek> Seek for BufReader<R> {
492492 )
493493 } )
494494 }
495+
496+ /// Seeks relative to the current position.
497+ ///
498+ /// If the new position lies within the buffer, the buffer will not be
499+ /// flushed, allowing for more efficient seeks. This method does not return
500+ /// the location of the underlying reader, so the caller must track this
501+ /// information themselves if it is required.
502+ fn seek_relative ( & mut self , offset : i64 ) -> io:: Result < ( ) > {
503+ self . seek_relative ( offset)
504+ }
495505}
496506
497507impl < T : ?Sized > SizeHint for BufReader < T > {
Original file line number Diff line number Diff line change @@ -1957,6 +1957,32 @@ pub trait Seek {
19571957 fn stream_position ( & mut self ) -> Result < u64 > {
19581958 self . seek ( SeekFrom :: Current ( 0 ) )
19591959 }
1960+
1961+ /// Seeks relative to the current position.
1962+ ///
1963+ /// This is equivalent to `self.seek(SeekFrom::Current(offset))`.
1964+ ///
1965+ /// # Example
1966+ ///
1967+ /// ```no_run
1968+ /// #![feature(seek_seek_relative)]
1969+ /// use std::{
1970+ /// io::{self, Seek},
1971+ /// fs::File,
1972+ /// };
1973+ ///
1974+ /// fn main() -> io::Result<()> {
1975+ /// let mut f = File::open("foo.txt")?;
1976+ /// f.seek_relative(10)?;
1977+ /// assert_eq!(f.stream_position()?, 10);
1978+ /// Ok(())
1979+ /// }
1980+ /// ```
1981+ #[ unstable( feature = "seek_seek_relative" , issue = "none" ) ]
1982+ fn seek_relative ( & mut self , offset : i64 ) -> Result < ( ) > {
1983+ self . seek ( SeekFrom :: Current ( offset) ) ?;
1984+ Ok ( ( ) )
1985+ }
19601986}
19611987
19621988/// Enumeration of possible methods to seek within an I/O object.
You can’t perform that action at this time.
0 commit comments