In my code I am setting the length of file to 0 using the set_len() method.
Then I am writing to it using the write_all() method.
I was able to recreate the bug using this small program.
use std::io::Write;
fn main() -> Result<(), Box<dyn std::error::Error>>{
let mut file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.open("thing.txt")?;
// Everything writes fine here
file.write_all(b"PLACEHOLDER")?;
file.set_len(0)?;
// File output is �����������PLACEHOLDER-AGAIN
file.write_all(b"PLACEHOLDER-AGAIN")?;
Ok(())
}
Am I doing something incorrectly?
I would assume the file output would be PLACEHOLDER-AGAIN