use std::path::PathBuf; fn main() { // We don't need anything fancy here now if std::env::args().len() != 2 { eprintln!( "usage: popline \n\ removes the first line of a file,\ writes it back to disk without that line" ); std::process::exit(1); } // A panic is fine, really; it'll be caught while writing let file = PathBuf::from(std::env::args().nth(1).unwrap()); let string = std::fs::read_to_string(&file).unwrap(); let mut lines = string.lines(); let line = match lines.next() { None => { std::process::exit(0); } Some(line) => line, }; let write = lines.collect::>().join("\n"); std::fs::write(file, write).unwrap(); println!("{line}"); }