kvarn::prelude

Trait Seek

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

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

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.

§Examples

Files implement Seek:

use std::io;
use std::io::prelude::*;
use std::fs::File;
use std::io::SeekFrom;

fn main() -> io::Result<()> {
    let mut f = File::open("foo.txt")?;

    // move the cursor 42 bytes from the start of the file
    f.seek(SeekFrom::Start(42))?;
    Ok(())
}

Required Methods§