std-method
Seek::rewind and stream_position
Rewind returns to the beginning. stream_position reports the current logical position of a seekable stream. Both may fail for an underlying I/O reason. Expected stdout (not executed): 1 0 Common mistake: Assuming rewind clears or truncates the underlying data.
Formal Syntax & Structure
rust syntaxrust
reader.rewind() -> io::Result<()>; reader.stream_position() -> io::Result<u64>Working Example
Example Snippetrust
fn main() { use std::io::{Cursor, Read, Seek}; let mut c = Cursor::new(b"ab"); let mut byte = [0]; c.read_exact(&mut byte).unwrap(); println!("{}", c.stream_position().unwrap()); c.rewind().unwrap(); println!("{}", c.stream_position().unwrap());}