Rust

Rust

Made by DeepSource

Found manual implementation of stream_position(..) RS-W1109

Anti-pattern
Minor
Autofix

The Seek trait provides the Seek::stream_position(&mut self) method, which is functionally identical to Self::seek(&mut self, SeekFrom::Current(0)). Consider avoiding the reimplementation.

Bad practice

fn foo() -> io::Result<()> {
    let mut f = File::create("foo.txt")?;
    f.write_all(b"Hello")?;
    eprintln!("Written {} bytes", f.seek(SeekFrom::Current(0))?);
}

Recommended

fn foo() -> io::Result<()> {
    let mut f = File::create("foo.txt")?;
    f.write_all(b"Hello")?;
    eprintln!("Written {} bytes", f.stream_position()?);
}