RS.CLIPPY.SEEK_FROM_CURRENT

Use dedicated method for seek from current position

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: seek_from_current. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks if the seek method of the Seek trait is called with SeekFrom::Current(0), and if it is, suggests using stream_position instead.

Why is this bad?

Readability. Use dedicated method.

Example

use std::fs::File;
use std::io::{self, Write, Seek, SeekFrom};

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

    Ok(())
}

Use instead:

use std::fs::File;
use std::io::{self, Write, Seek, SeekFrom};

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

    Ok(())
}

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)