Closed
Description
What it does
Suggests to use stream_position()
over seek(SeekFrom::Current(0))
.
Categories (optional)
- Kind: clippy::style
Since Rust 1.51, the Seek trait has a stream_position method.
Using it makes the intent more clear over seek
.
Drawbacks
None.
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"Hi!")?;
eprintln!("Written {} bytes.", f.seek(SeekFrom::Current(0))?);
Ok(())
}
Could be written as:
use std::fs::File;
use std::io::{self, Write, Seek};
fn main() -> io::Result<()> {
let mut f = File::create("foo.txt")?;
f.write_all(b"Hi!")?;
eprintln!("Written {} bytes.", f.stream_position()?);
Ok(())
}