1
Fork 0
mirror of https://github.com/Steffo99/micronfig.git synced 2024-12-22 20:14:18 +00:00

Use unwrap_or_else and panic! instead of expect and format!

This commit is contained in:
Steffo 2024-12-19 06:27:49 +01:00
parent 4da9dea5d6
commit bafdbd888b
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 3 additions and 3 deletions

View file

@ -21,7 +21,7 @@ pub fn parse_dotenv<P>(value: P) -> Option<DotEnv>
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<OsString, String> = HashMap::new();

View file

@ -13,11 +13,11 @@ pub fn get(key: &OsStr) -> Option<String> {
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)
}