1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 07:30:05 +08:00

chore: rm read_json_config

This commit is contained in:
2020-09-10 01:05:27 +08:00
parent 1917b23c27
commit 6b86709137
2 changed files with 4 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "rust_util"
version = "0.6.10"
version = "0.6.11"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
description = "Hatter's Rust Util"
@@ -9,12 +9,12 @@ readme = "README.md"
[features]
default = [] #["serde", "serde_json"]
use_serde = ["serde", "serde_json"]
# use_serde = ["serde", "serde_json"]
[dependencies]
libc = "0.2.65"
term = "0.5.2"
term_size = "0.3.1"
lazy_static = "1.3.0"
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
# serde = { version = "1.0", features = ["derive"], optional = true }
# serde_json = { version = "1.0", optional = true }

View File

@@ -1,11 +1,9 @@
use std::{
env,
fs::{ self, File },
io::{ Lines, BufReader },
path::{ Path, PathBuf },
};
use crate::{
iff,
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> {
match config {
Some(config_str) => Some(PathBuf::from(config_str)),