aboutsummaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-09-17 23:55:58 +0200
committerTom Smeding <tom.smeding@gmail.com>2021-01-28 22:20:13 +0100
commit27e28284fbf5fbbef1bb62cebb5eba6456958be1 (patch)
tree6e97a4c6c4c2ca6116a69bff16866b956f072144 /rust
parent7466f90f3b50505431ec63e775b70dbac98f151d (diff)
rust: Don't crash when we can't write debug.txt
Diffstat (limited to 'rust')
-rw-r--r--rust/src/main.rs8
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 {