From bafdbd888bbc619b41f71bc57e9f2298902cb559 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 19 Dec 2024 06:27:49 +0100 Subject: [PATCH] Use `unwrap_or_else` and `panic!` instead of `expect` and `format!` --- micronfig/src/envdot.rs | 2 +- micronfig/src/envfiles.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/micronfig/src/envdot.rs b/micronfig/src/envdot.rs index 500a0a8..c7514ec 100644 --- a/micronfig/src/envdot.rs +++ b/micronfig/src/envdot.rs @@ -21,7 +21,7 @@ pub fn parse_dotenv

(value: P) -> Option let mut contents: String = String::new(); file.read_to_string(&mut contents) - .expect(&format!("to be able to read {value:?}")); + .unwrap_or_else(|_| panic!("to be able to read {value:?}")); let mut keys: HashMap = HashMap::new(); diff --git a/micronfig/src/envfiles.rs b/micronfig/src/envfiles.rs index aa11561..4c50e50 100644 --- a/micronfig/src/envfiles.rs +++ b/micronfig/src/envfiles.rs @@ -13,11 +13,11 @@ pub fn get(key: &OsStr) -> Option { let path = std::path::PathBuf::from(path); let mut file = std::fs::File::open(&path) - .expect(&format!("to be able to open file at {path:?}")); + .unwrap_or_else(|_| panic!("to be able to open file at {path:?}")); let mut data = String::new(); file.read_to_string(&mut data) - .expect(&format!("to be able to read from file at {path:?}")); + .unwrap_or_else(|_| panic!("to be able to read from file at {path:?}")); Some(data) }