mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
chore: rm read_json_config
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.6.10"
|
version = "0.6.11"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Hatter's Rust Util"
|
description = "Hatter's Rust Util"
|
||||||
@@ -9,12 +9,12 @@ readme = "README.md"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [] #["serde", "serde_json"]
|
default = [] #["serde", "serde_json"]
|
||||||
use_serde = ["serde", "serde_json"]
|
# use_serde = ["serde", "serde_json"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.65"
|
libc = "0.2.65"
|
||||||
term = "0.5.2"
|
term = "0.5.2"
|
||||||
term_size = "0.3.1"
|
term_size = "0.3.1"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
# serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
serde_json = { version = "1.0", optional = true }
|
# serde_json = { version = "1.0", optional = true }
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fs::{ self, File },
|
fs::{ self, File },
|
||||||
io::{ Lines, BufReader },
|
io::{ Lines, BufReader },
|
||||||
path::{ Path, PathBuf },
|
path::{ Path, PathBuf },
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
iff,
|
iff,
|
||||||
util_os,
|
util_os,
|
||||||
@@ -118,18 +116,6 @@ 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)>> 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) => {
|
|
||||||
let json_config: T = serde_json::from_reader(std::fs::File::open(&config_path_buf)?)?;
|
|
||||||
Ok(Some((config_path_buf, json_config)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_config(config: Option<String>, files: &[String]) -> Option<PathBuf> {
|
pub fn read_config(config: Option<String>, files: &[String]) -> Option<PathBuf> {
|
||||||
match config {
|
match config {
|
||||||
Some(config_str) => Some(PathBuf::from(config_str)),
|
Some(config_str) => Some(PathBuf::from(config_str)),
|
||||||
|
|||||||
Reference in New Issue
Block a user