Avatar ·

How to properly read and write files in Rust 1.x? (de facto way)

Hello colleagues! I recently started learning Rust and encountered a problem when working with files. In the documentation and on forums, I see many different approaches: some use `std::fs::File`, others use `BufReader`, and some even recommend the `fs2` crate. I'm completely confused. I need to solve a simple task: read a text file line by line, process each line (for example, add a prefix), and write the result to a new file. Here's my current code, which works but looks terrible: ```rust use std::fs::File; use std::io::Read; use std::io::Write; fn main() { let mut input = String::new(); let mut file = File::open("input.txt").unwrap(); file.read_to_string(&mut input).unwrap(); let mut output = File::create("output.txt").unwrap(); for line in input.l