Skip to content

Commit 96ce220

Browse files
committed
refactor(features): rm all optional deps and features
1 parent c2cd6b9 commit 96ce220

File tree

11 files changed

+31
-85
lines changed

11 files changed

+31
-85
lines changed

Cargo.toml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,23 @@ exclude = [
1313
]
1414

1515
[dependencies]
16-
chrono = {version = "0.4", optional = true}
17-
lazy_static = {version = "1", optional = true}
18-
miniz_oxide = {version = "0.7", optional = true}
16+
chrono = {version = "0.4" }
17+
lazy_static = {version = "1" }
18+
miniz_oxide = {version = "0.7" }
1919

2020
# anyhow = "1"
2121
thiserror = "1"
22-
log = {version = "0.4", optional = true}
22+
log = {version = "0.4" }
2323

2424
[dependencies.serde]
2525
version = "1"
26-
optional = true
2726
features = ["derive"]
2827
# default-features = false
2928

3029
[dependencies.encoding_rs]
3130
version = "0.8"
32-
optional = true
3331
features = ["fast-gb-hanzi-encode"]
3432

35-
[features]
36-
default = ["full"]
37-
full = ["file", "tcp", "encoding_rs", "chrono"]
38-
tcp = ["miniz_oxide", "lazy_static", "serde", "log"]
39-
file = []
40-
4133
[dev-dependencies]
4234
# backtrace 是在 cargo test 无法并行的情况下 用于产生 test name (从而产生 snapshot name )
4335
insta = "1"

rustdx-cmd/Cargo.toml

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,32 @@ exclude = [
1515

1616
[dependencies]
1717
anyhow = "1"
18-
argh = {version = "0.1" , optional = true}
19-
calamine = {version = "0.19", optional = true}
20-
futures = {version = "0.3" , optional = true}
21-
tokio = {version = "1", features = ["rt-multi-thread", "macros"] , optional = true}
22-
# rustdx = {path = "../" , optional = true}
23-
reqwest = {version = "0.11", optional = true}
24-
bytes = {version = "1.1" , optional = true}
25-
csv = {version = "1.1" , optional = true}
26-
log = {version = "0.4" , optional = true}
27-
chrono = {version = "0.4" , optional = true}
28-
serde_json = {version = "1", optional = true}
29-
lazy_static = {version = "1", optional = true}
30-
mini-redis = {version = "0.4", optional = true}
31-
subprocess = {version = "0.2", optional = true}
32-
simplelog = {version ="0.12", optional = true}
33-
miniz_oxide = {version ="0.7", optional = true}
18+
argh = {version = "0.1" }
19+
calamine = {version = "0.19"}
20+
futures = {version = "0.3" }
21+
tokio = {version = "1", features = ["rt-multi-thread", "macros"] }
22+
# rustdx = {path = "../" }
23+
reqwest = {version = "0.11"}
24+
bytes = {version = "1.1" }
25+
csv = {version = "1.1" }
26+
log = {version = "0.4" }
27+
chrono = {version = "0.4" }
28+
serde_json = {version = "1"}
29+
lazy_static = {version = "1"}
30+
mini-redis = {version = "0.4"}
31+
subprocess = {version = "0.2"}
32+
simplelog = {version ="0.12"}
33+
miniz_oxide = {version ="0.7"}
3434

3535
[dependencies.rustdx]
3636
version = "0.3.0"
37-
optional = true
3837
path = "../"
39-
default-features = false
40-
features = ["serde", "file"]
4138

4239
[dependencies.serde]
4340
version = "1"
44-
optional = true
4541
features = ["derive"]
4642

47-
[features]
48-
default = ["bin"]
49-
bin = ["rustdx", "tokio/rt", "tokio/rt-multi-thread", "futures", "argh", "calamine", "lazy_static", "reqwest", "csv", "subprocess", "reqwest/json", "serde", "serde_json", "chrono"]
50-
excel = ["calamine", "reqwest", "tokio/rt", "tokio/rt-multi-thread", "futures"]
51-
clickhouse = ["tokio/macros", "tokio/sync", "csv"]
52-
5343
[[bin]]
5444
name = "rustdx"
5545
path = "src/main.rs"
56-
required-features = ["bin"]
57-
58-
[[example]]
59-
name = "excel"
60-
path = "examples/excel.rs"
61-
required-features = ["excel"]
62-
63-
[[example]]
64-
name = "excel_and_online"
65-
path = "examples/excel_and_online.rs"
66-
required-features = ["excel"]
67-
68-
[[example]]
69-
name = "clickhouse-cmd"
70-
path = "examples/clickhouse-cmd.rs"
71-
required-features = ["clickhouse"]
7246

73-
[[example]]
74-
name = "tcp"
75-
path = "examples/tcp.rs"
76-
required-features = ["rustdx/tcp"]

rustdx-cmd/examples/excel.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ enum Exchange {
4444
Szse,
4545
}
4646

47-
fn read_excel(path: &str, ex: Exchange) -> Result<Sheets> {
47+
type Reader = std::io::BufReader<std::fs::File>;
48+
fn read_excel(path: &str, ex: Exchange) -> Result<Sheets<Reader>> {
4849
let now = Instant::now();
4950
let mut workbook = open_workbook_auto(&path)?;
5051
println!(

src/bytes_helper.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ pub fn date_string(x: u32) -> String {
4747
format!("{}-{}{}-{}{}", y, fill(m), m, fill(d), d)
4848
}
4949

50-
#[cfg(feature = "serde")]
5150
pub fn ser_date_string<S>(date: &u32, serializer: S) -> Result<S::Ok, S::Error>
5251
where
5352
S: serde::Serializer,
5453
{
5554
serializer.serialize_str(&crate::bytes_helper::date_string(*date))
5655
}
5756

58-
#[cfg(feature = "serde")]
5957
pub fn ser_code_string<S>(code: &u32, serializer: S) -> Result<S::Ok, S::Error>
6058
where
6159
S: serde::Serializer,

src/file/day/fq.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use crate::{
66
use std::path::Path;
77

88
/// 注意:成交量的单位为 “手”,而不是股。在通达信和交易所数据里,单位为股。
9-
#[derive(Debug, Clone)]
10-
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
9+
#[derive(Debug, Clone, serde::Serialize)]
1110
pub struct Day {
1211
pub date: String,
1312
pub code: String,

src/file/day/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::path::Path;
22

3-
#[cfg(feature = "serde")]
43
use {
54
crate::bytes_helper::{ser_code_string, ser_date_string},
65
serde::{Serialize, Serializer},
@@ -17,23 +16,21 @@ pub mod fq;
1716
/// 开启 `serde` feature 时,此结构体的序列化 (serialize) 时:
1817
/// 1. `date` 为 `年-月-日` 格式
1918
/// 2. `code` 为 6 位字符串的股票代码
20-
#[derive(Debug, Clone, Copy)]
21-
#[cfg_attr(feature = "serde", derive(Serialize))]
19+
#[derive(Debug, Clone, Copy, Serialize)]
2220
pub struct Day {
23-
#[cfg_attr(feature = "serde", serde(serialize_with = "ser_date_string"))]
21+
#[serde(serialize_with = "ser_date_string")]
2422
pub date: u32,
25-
#[cfg_attr(feature = "serde", serde(serialize_with = "ser_code_string"))]
23+
#[serde(serialize_with = "ser_code_string")]
2624
pub code: u32,
2725
pub open: f32,
2826
pub high: f32,
2927
pub low: f32,
3028
pub close: f32,
3129
pub amount: f32,
32-
#[cfg_attr(feature = "serde", serde(serialize_with = "ser_vol"))]
30+
#[serde(serialize_with = "ser_vol")]
3331
pub vol: u32,
3432
}
3533

36-
#[cfg(feature = "serde")]
3734
fn ser_vol<S>(vol: &u32, serializer: S) -> Result<S::Ok, S::Error>
3835
where
3936
S: Serializer,
@@ -97,7 +94,6 @@ impl Day {
9794
}
9895

9996
/// chrono 格式的日期:用于某些序列化或者与时间相关的计算
100-
#[cfg(feature = "chrono")]
10197
pub fn ymd(&self) -> chrono::naive::NaiveDate {
10298
let [y, m, d] = self.ymd_arr();
10399
chrono::naive::NaiveDate::from_ymd_opt(y as i32, m, d).unwrap()

src/file/gbbq/fq.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use super::Gbbq;
22
use crate::file::day::Day;
33

4-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
5-
#[derive(Debug, Clone)]
4+
#[derive(serde::Deserialize, Debug, Clone)]
65
pub struct Factor {
76
pub date: String,
87
pub code: String,
9-
#[cfg_attr(feature = "serde", serde(rename(deserialize = "close")))]
8+
#[serde(rename(deserialize = "close"))]
109
pub preclose: f64,
1110
pub factor: f64,
1211
}
1312

14-
#[cfg(feature = "serde")]
1513
impl Factor {
1614
/// 根据前收、收盘价(最新价)和前一日的因子计算当日的复权因子。
1715
#[inline]

src/file/gbbq/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ pub type StockGbbq<'a> = HashMap<u32, Vec<Gbbq<'a>>>;
1313
/// ## 注意
1414
/// 开启 `serde` feature 时,此结构体的序列化 (serialize) 时:
1515
/// `date` 为 `年-月-日` 格式。
16-
#[derive(Debug, Clone)]
17-
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
16+
#[derive(Debug, Clone, serde::Serialize)]
1817
pub struct Gbbq<'a> {
1918
pub market: u8,
2019
/// 6 位股票代码
2120
pub code: &'a str,
2221
/// 日期
23-
#[cfg_attr(feature = "serde", serde(serialize_with = "ser_date_string"))]
22+
#[serde(serialize_with = "ser_date_string")]
2423
pub date: u32,
2524
/// 信息类型
2625
///

src/file/lc/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ impl Lc {
6767

6868
/// 转化成用于(反)序列化的数据类型:
6969
/// 6 位字符串的股票代码;%Y-%m-%d 字符串格式的日期;f64 类型的成交额;u64 类型的 vol 。
70-
#[cfg(feature = "serde")]
7170
pub fn into_serde_type(self) -> LcSerde {
7271
LcSerde {
7372
datetime: self.datetime_string(),
@@ -105,7 +104,6 @@ impl Lc {
105104
}
106105

107106
/// chrono 格式的日期:用于某些序列化或者与时间相关的计算
108-
#[cfg(feature = "chrono")]
109107
pub fn datetime(&self) -> chrono::naive::NaiveDateTime {
110108
use chrono::naive::NaiveDate;
111109
const ERR: &str = "日期格式不对";
@@ -121,7 +119,6 @@ impl Lc {
121119
/// 用于序列化:比如写入到 csv
122120
///
123121
/// 此结构体暂时待定,未来可能更改。
124-
#[cfg(feature = "serde")]
125122
#[derive(Debug, Clone, serde::Serialize)]
126123
pub struct LcSerde {
127124
/// `date` 为 `%Y-%m-%d H:M` 文本格式

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
pub mod bytes_helper;
77

8-
#[cfg(feature = "file")]
98
pub mod file;
109

11-
#[cfg(feature = "tcp")]
1210
pub mod tcp;
1311

1412
use thiserror::Error;

src/tcp/basic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl SecurityList {
115115
}
116116
}
117117

118-
#[cfg(feature = "encoding_rs")]
119118
impl Tdx for SecurityList {
120119
type Item = [SecurityListData];
121120

@@ -176,7 +175,6 @@ impl SecurityListData {
176175
/// reversed_bytes2,
177176
/// ) = struct.unpack("<6sH8s4sBI4s", bytes) # python 表示方式
178177
/// ```
179-
#[cfg(feature = "encoding_rs")]
180178
pub fn parse(bytes: &[u8]) -> Self {
181179
let code = unsafe { std::str::from_utf8_unchecked(&bytes[0..6]) }.into();
182180
let (name, encoding_used, had_errors) = encoding_rs::GBK.decode(&bytes[8..16]);

0 commit comments

Comments
 (0)