From 9f66a85e8b9d7f34d1ef0b39ecb816e082c67db2 Mon Sep 17 00:00:00 2001 From: Konippi Date: Thu, 1 Aug 2024 22:22:29 +0900 Subject: [PATCH] refactor: how to build path in reader --- src/reader.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 7c1251b..fc2bc17 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3,12 +3,11 @@ use std::{env, fs, path::PathBuf}; /// Read seeds from specified file pub fn read_file(filename: &str, base_dir: &str) -> Result { - let mut path = PathBuf::new(); - if let Ok(current_base) = env::var("CARGO_MANIFEST_DIR") { - path.push(current_base) - } - path.push(base_dir); - path.push(filename); + let path = env::var("CARGO_MANIFEST_DIR") + .map(PathBuf::from) + .unwrap_or_default() + .join(base_dir) + .join(filename); fs::read_to_string(&path) .map_err(|err| anyhow::anyhow!("Can't open the file: {:?}\n err: {}", path, err))