diff options
Diffstat (limited to 'rust/src/main.rs')
-rw-r--r-- | rust/src/main.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs index 8dc5163..4b79973 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -21,14 +21,16 @@ use crate::error::IntoIOError; mod editor; mod error; -static DEBUG_FILE: Lazy<Mutex<File>> = Lazy::new(|| { +static DEBUG_FILE: Lazy<Mutex<Option<File>>> = Lazy::new(|| { Mutex::new( OpenOptions::new().write(true).truncate(true).create(true) - .open("debug.txt").unwrap()) + .open("debug.txt").ok()) }); fn debug_write(s: &str) { - writeln!(DEBUG_FILE.lock().unwrap(), "{}", s).unwrap(); + let file = DEBUG_FILE.lock().unwrap(); + file.as_ref() + .map(|mut file| writeln!(file, "{}", s).unwrap()); } macro_rules! debug { |