@@ -692,17 +692,38 @@ pub trait Write {
692
692
}
693
693
}
694
694
695
- /// An object implementing `Seek` internally has some form of cursor which can
696
- /// be moved within a stream of bytes.
695
+ /// The `Seek` trait provides a cursor which can be moved within a stream of
696
+ /// bytes.
697
697
///
698
698
/// The stream typically has a fixed size, allowing seeking relative to either
699
699
/// end or the current offset.
700
+ ///
701
+ /// # Examples
702
+ ///
703
+ /// [`File`][file]s implement `Seek`:
704
+ ///
705
+ /// [file]: ../std/fs/struct.File.html
706
+ ///
707
+ /// ```
708
+ /// use std::io;
709
+ /// use std::fs::File;
710
+ /// use std::io::Seek;
711
+ /// use std::io::SeekFrom;
712
+ ///
713
+ /// # fn foo() -> io::Result<()> {
714
+ /// let mut f = try!(File::open("foo.txt"));
715
+ ///
716
+ /// // move the cursor 42 bytes from the start of the file
717
+ /// f.seek(SeekFrom::Start(42)).unwrap();
718
+ /// # Ok(())
719
+ /// # }
720
+ /// ```
700
721
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
701
722
pub trait Seek {
702
- /// Seek to an offset, in bytes, in a stream
723
+ /// Seek to an offset, in bytes, in a stream.
703
724
///
704
- /// A seek beyond the end of a stream is allowed, but seeking before offset
705
- /// 0 is an error .
725
+ /// A seek beyond the end of a stream is allowed, but implementation
726
+ /// defined .
706
727
///
707
728
/// The behavior when seeking past the end of the stream is implementation
708
729
/// defined.
@@ -712,7 +733,7 @@ pub trait Seek {
712
733
///
713
734
/// # Errors
714
735
///
715
- /// Seeking to a negative offset is considered an error
736
+ /// Seeking to a negative offset is considered an error.
716
737
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
717
738
fn seek ( & mut self , pos : SeekFrom ) -> Result < u64 > ;
718
739
}
0 commit comments