From de9ca81b652dad9799547be319890286681cb084 Mon Sep 17 00:00:00 2001 From: MultisampledNight Date: Sat, 20 Jan 2024 21:47:33 +0100 Subject: [PATCH] chore: appease clippy --- crates/app/src/config/config_file.rs | 7 +++++-- crates/app/src/error_reporting.rs | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/app/src/config/config_file.rs b/crates/app/src/config/config_file.rs index a0c4db1..a8ba835 100644 --- a/crates/app/src/config/config_file.rs +++ b/crates/app/src/config/config_file.rs @@ -40,10 +40,13 @@ pub(super) fn find_config_file() -> Result { impl Configs { pub fn read(p: PathBuf) -> Result { - match p.extension().map(|v| v.to_str().unwrap()) { + match p + .extension() + .map(|v| v.to_str().expect("config path to be UTF-8")) + { Some("ron") => Ok(serde_json::from_str(&fs::read_to_string(p)?)?), Some("json") => Ok(ron::from_str(&fs::read_to_string(p)?)?), - e => Err(ConfigError::UnknownExtension(e.map(|v| v.to_owned()))), + e => Err(ConfigError::UnknownExtension(e.map(str::to_string))), } } } diff --git a/crates/app/src/error_reporting.rs b/crates/app/src/error_reporting.rs index 33ffff6..bc4c44b 100644 --- a/crates/app/src/error_reporting.rs +++ b/crates/app/src/error_reporting.rs @@ -3,12 +3,12 @@ use std::process; use ron::error::Position; /// Report an `Error` from the `serde_json` crate -pub fn report_serde_json_err(src: &str, err: serde_json::Error) -> ! { +pub fn report_serde_json_err(src: &str, err: &serde_json::Error) -> ! { report_serde_err(src, err.line(), err.column(), err.to_string()) } /// Report a `SpannedError` from the `ron` crate -pub fn report_serde_ron_err(src: &str, err: ron::error::SpannedError) -> ! { +pub fn report_serde_ron_err(src: &str, err: &ron::error::SpannedError) -> ! { let Position { line, col } = err.position; report_serde_err(src, line, col, err.to_string()) } @@ -23,8 +23,8 @@ fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! { .with_message(msg) .with_note("We'd like to give better errors, but serde errors are horrible to work with...") .finish() - .print(("test", Source::from(src))) - .unwrap(); + .eprint(("test", Source::from(src))) + .expect("writing error to stderr failed"); process::exit(1); }