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