mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
fix: use serde
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.6.9"
|
||||
version = "0.6.10"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -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