Seek

Trait Seek 

Source
pub trait Seek: ErrorType {
    // Required method
    fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;

    // Provided methods
    fn rewind(&mut self) -> Result<(), Self::Error> { ... }
    fn stream_position(&mut self) -> Result<u64, Self::Error> { ... }
    fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> { ... }
}
Expand description

Blocking seek within streams.\

The Seek trait provides a cursor which can be moved within a stream of bytes.

The stream typically has a fixed size, allowing seeking relative to either end or the current offset.

This trait is the embedded-io equivalent of std::io::Seek.

Required Methods§

Source

fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>

Seek to an offset, in bytes, in a stream. A seek beyond the end of a stream is allowed, but behavior is defined by the implementation.

If the seek operation completed successfully, this method returns the new position from the start of the stream. That position can be used later with SeekFrom::Start.

§Errors

Seeking can fail, for example because it might involve flushing a buffer.

Seeking to a negative offset is considered an error.

Provided Methods§

Source

fn rewind(&mut self) -> Result<(), Self::Error>

Rewind to the beginning of a stream.

This is a convenience method, equivalent to seek(SeekFrom::Start(0)).

§Errors

Rewinding can fail, for example because it might involve flushing a buffer.

Source

fn stream_position(&mut self) -> Result<u64, Self::Error>

Returns the current seek position from the start of the stream.

This is equivalent to self.seek(SeekFrom::Current(0)).

Source

fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error>

Seeks relative to the current position.

This is equivalent to self.seek(SeekFrom::Current(offset)) but doesn’t return the new position which can allow some implementations to perform more efficient seeks.

Implementations on Foreign Types§

Source§

impl<T: ?Sized + Seek> Seek for &mut T

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>

Source§

fn rewind(&mut self) -> Result<(), Self::Error>

Source§

fn stream_position(&mut self) -> Result<u64, Self::Error>

Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error>

Source§

impl<T: ?Sized + Seek> Seek for Box<T>

Available on crate features std or alloc only.
Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>

Source§

fn rewind(&mut self) -> Result<(), Self::Error>

Source§

fn stream_position(&mut self) -> Result<u64, Self::Error>

Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error>

Implementors§