From 34fe4da417ccd53320105a314f7eaf43104cfef8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 30 Jul 2023 15:08:26 +0100 Subject: [PATCH] box up FileEnv's functions --- src/file/env.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/file/env.rs b/src/file/env.rs index 005ced2..5635b67 100644 --- a/src/file/env.rs +++ b/src/file/env.rs @@ -1,15 +1,19 @@ use std::fs::{File, OpenOptions}; use std::io::Write; +pub type FileOpenFn = Box std::io::Result>; + +pub type FileAppendLineFn = Box std::io::Result<()>>; + pub struct FileEnv { - pub open: FileOpen, - pub append_line: FileAppendLine, + pub open: FileOpenFn, + pub append_line: FileAppendLineFn, } impl Default for FileEnv { fn default() -> Self { Self { - open: |path| File::open(path), - append_line: |file_name, line| { + open: Box::new(|path| File::open(path)), + append_line: Box::new(|file_name, line| { let mut file = OpenOptions::new() .write(true) .append(true) @@ -18,9 +22,7 @@ impl Default for FileEnv { .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<()>;