use std::fs::{File, OpenOptions}; use std::io::Write; pub struct FileEnv { pub open: FileOpen, pub append_line: FileAppendLine, } impl Default for FileEnv { fn default() -> Self { Self { open: |path| File::open(path), append_line: |file_name, line| { let mut file = OpenOptions::new() .write(true) .append(true) .create(true) .open(file_name) .unwrap(); writeln!(file, "{}", line)?; Ok(()) }, } } } pub type FileOpen = fn(path: &str) -> std::io::Result; pub type FileAppendLine = fn(paht: &str, line: &str) -> std::io::Result<()>;