Skip to main content

Seek

Trait Seek 

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

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

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

See [std::io::Seek] for more details.

Required Methods§

Source

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

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.

Provided Methods§

Source

fn rewind(&mut self) -> Result<(), IoError>

Rewind to the beginning of a stream.

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

Source

fn stream_position(&mut self) -> Result<u64, IoError>

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

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

Source

fn stream_len(&mut self) -> Result<u64, IoError>

Returns the length of this stream (in bytes).

Source

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

Seeks relative to the current position.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S> Seek for &mut S
where S: Seek + ?Sized,

Source§

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

Source§

fn rewind(&mut self) -> Result<(), IoError>

Source§

fn stream_len(&mut self) -> Result<u64, IoError>

Source§

fn stream_position(&mut self) -> Result<u64, IoError>

Source§

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

Source§

impl<S> Seek for Box<S>
where S: Seek + ?Sized,

Available on crate feature alloc only.
Source§

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

Source§

fn rewind(&mut self) -> Result<(), IoError>

Source§

fn stream_len(&mut self) -> Result<u64, IoError>

Source§

fn stream_position(&mut self) -> Result<u64, IoError>

Source§

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

Implementors§

Source§

impl Seek for Empty

Source§

impl<R> Seek for BufReader<R>
where R: Seek + ?Sized,

Source§

impl<T> Seek for Cursor<T>
where T: AsRef<[u8]>,

Source§

impl<T> Seek for Take<T>
where T: Seek,

Source§

impl<W> Seek for BufWriter<W>
where W: Write + Seek + ?Sized,