From 27e28284fbf5fbbef1bb62cebb5eba6456958be1 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 17 Sep 2020 23:55:58 +0200 Subject: rust: Don't crash when we can't write debug.txt --- rust/src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'rust/src') 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> = Lazy::new(|| { +static DEBUG_FILE: Lazy>> = 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 { -- cgit v1.2.3-70-g09d2