@@ -469,23 +469,59 @@ pub trait Write: ErrorType {
469
469
}
470
470
}
471
471
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.
473
479
///
474
480
/// This trait is the `embedded-io` equivalent of [`std::io::Seek`].
475
481
pub trait Seek : ErrorType {
476
482
/// 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.
477
495
fn seek ( & mut self , pos : SeekFrom ) -> Result < u64 , Self :: Error > ;
478
496
479
497
/// 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.
480
504
fn rewind ( & mut self ) -> Result < ( ) , Self :: Error > {
481
505
self . seek ( SeekFrom :: Start ( 0 ) ) ?;
482
506
Ok ( ( ) )
483
507
}
484
508
485
509
/// Returns the current seek position from the start of the stream.
510
+ ///
511
+ /// This is equivalent to `self.seek(SeekFrom::Current(0))`.
486
512
fn stream_position ( & mut self ) -> Result < u64 , Self :: Error > {
487
513
self . seek ( SeekFrom :: Current ( 0 ) )
488
514
}
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
+ }
489
525
}
490
526
491
527
/// Get whether a reader is ready.
0 commit comments