mirror of
https://github.com/jht5945/rust_util.git
synced 2026-01-12 23:30:05 +08:00
Compare commits
3 Commits
0576c23c5a
...
6b86709137
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b86709137 | |||
| 1917b23c27 | |||
| 3db1fb8130 |
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.6.8"
|
||||
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 }
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
|
||||
use std::{
|
||||
env,
|
||||
fs::{ self, File },
|
||||
io::{ Lines, BufReader },
|
||||
path::{ Path, PathBuf },
|
||||
};
|
||||
|
||||
use crate::{
|
||||
iff,
|
||||
util_os,
|
||||
@@ -118,19 +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)>> {
|
||||
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)?)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_config(config: Option<String>, files: &[String]) -> Option<PathBuf> {
|
||||
match config {
|
||||
Some(config_str) => Some(PathBuf::from(config_str)),
|
||||
|
||||
Reference in New Issue
Block a user