@@ -469,23 +469,59 @@ pub trait Write: ErrorType {
469469 }
470470}
471471
472- /// Blocking seek within streams.
472+ /// Blocking seek within streams.\
473+ ///
474+ /// The `Seek` trait provides a cursor which can be moved within a stream of
475+ /// bytes.
476+ ///
477+ /// The stream typically has a fixed size, allowing seeking relative to either
478+ /// end or the current offset.
473479///
474480/// This trait is the `embedded-io` equivalent of [`std::io::Seek`].
475481pub trait Seek : ErrorType {
476482 /// Seek to an offset, in bytes, in a stream.
483+ /// A seek beyond the end of a stream is allowed, but behavior is defined
484+ /// by the implementation.
485+ ///
486+ /// If the seek operation completed successfully,
487+ /// this method returns the new position from the start of the stream.
488+ /// That position can be used later with [`SeekFrom::Start`].
489+ ///
490+ /// # Errors
491+ ///
492+ /// Seeking can fail, for example because it might involve flushing a buffer.
493+ ///
494+ /// Seeking to a negative offset is considered an error.
477495 fn seek ( & mut self , pos : SeekFrom ) -> Result < u64 , Self :: Error > ;
478496
479497 /// Rewind to the beginning of a stream.
498+ ///
499+ /// This is a convenience method, equivalent to `seek(SeekFrom::Start(0))`.
500+ ///
501+ /// # Errors
502+ ///
503+ /// Rewinding can fail, for example because it might involve flushing a buffer.
480504 fn rewind ( & mut self ) -> Result < ( ) , Self :: Error > {
481505 self . seek ( SeekFrom :: Start ( 0 ) ) ?;
482506 Ok ( ( ) )
483507 }
484508
485509 /// Returns the current seek position from the start of the stream.
510+ ///
511+ /// This is equivalent to `self.seek(SeekFrom::Current(0))`.
486512 fn stream_position ( & mut self ) -> Result < u64 , Self :: Error > {
487513 self . seek ( SeekFrom :: Current ( 0 ) )
488514 }
515+
516+ /// Seeks relative to the current position.
517+ ///
518+ /// This is equivalent to `self.seek(SeekFrom::Current(offset))` but
519+ /// doesn't return the new position which can allow some implementations
520+ /// to perform more efficient seeks.
521+ fn seek_relative ( & mut self , offset : i64 ) -> Result < ( ) , Self :: Error > {
522+ self . seek ( SeekFrom :: Current ( offset) ) ?;
523+ Ok ( ( ) )
524+ }
489525}
490526
491527/// Get whether a reader is ready.
0 commit comments