conver File Results into crate Results

This commit is contained in:
Paul Campbell 2023-07-30 15:29:49 +01:00
parent 34fe4da417
commit fede0eebf1
2 changed files with 7 additions and 3 deletions

View file

@ -1,9 +1,11 @@
use crate::prelude::*;
use std::fs::{File, OpenOptions};
use std::io::Write;
pub type FileOpenFn = Box<dyn Fn(&str) -> std::io::Result<File>>;
pub type FileOpenFn = Box<dyn Fn(&str) -> Result<File>>;
pub type FileAppendLineFn = Box<dyn Fn(&str, &str) -> std::io::Result<()>>;
pub type FileAppendLineFn = Box<dyn Fn(&str, &str) -> Result<()>>;
pub struct FileEnv {
pub open: FileOpenFn,
@ -12,7 +14,7 @@ pub struct FileEnv {
impl Default for FileEnv {
fn default() -> Self {
Self {
open: Box::new(|path| File::open(path)),
open: Box::new(|path| Ok(File::open(path)?)),
append_line: Box::new(|file_name, line| {
let mut file = OpenOptions::new()
.write(true)

View file

@ -1,4 +1,6 @@
mod env;
pub mod read;
pub use env::FileAppendLineFn;
pub use env::FileEnv;
pub use env::FileOpenFn;