trait

Seek: reposition a byte stream

Seek moves a position in a seekable byte source or destination and returns the resulting offset. A pipe or other streaming source need not implement it. Expected stdout (not executed): C Common mistake: Assuming every Read implementation supports random access.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
fn main() {    use std::io::{Cursor, Seek, SeekFrom, Read};    let mut c = Cursor::new(b"ABCDE");    c.seek(SeekFrom::Start(2)).unwrap();    let mut byte = [0];    c.read_exact(&mut byte).unwrap();    println!("{}", byte[0] as char);}
Rust Reference