mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-29 00:20:04 +08:00
fix: use serde
This commit is contained in:
@@ -119,14 +119,13 @@ pub fn find_parents_exists_dir(dir: &str) -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "use_serde")]
|
||||
pub fn read_json_config<T>(config: Option<String>, files: &[String]) -> XResult<Option<(PathBuf, T)>> {
|
||||
pub fn read_json_config<T>(config: Option<String>, files: &[String]) -> XResult<Option<(PathBuf, T)>> where T: serde::de::DeserializeOwned {
|
||||
let config_path_buf_opt = read_config(config, files);
|
||||
match config_path_buf_opt {
|
||||
None => Ok(None),
|
||||
Some(config_path_buf) => {
|
||||
// information!("Read config: {}", config_path_buf);
|
||||
let config_content = fs::read_to_string(config_path_buf)?;
|
||||
Ok(Some((config_path_buf, serde_json::from_str(&config_content)?)))
|
||||
let json_config: T = serde_json::from_reader(std::fs::File::open(&config_path_buf)?)?;
|
||||
Ok(Some((config_path_buf, json_config)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user