Skip to content

Commit e702ae6

Browse files
Jeff Tsaijjeffcaii
authored andcommitted
feat: use cfg_if and once_cell
1 parent 8dddb71 commit e702ae6

File tree

11 files changed

+86
-70
lines changed

11 files changed

+86
-70
lines changed

rsocket-transport-tcp/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ default = []
1414
tls = ["tokio-native-tls"]
1515

1616
[dependencies]
17-
log = "0.4.13"
18-
futures = "0.3.10"
17+
log = "0.4.14"
18+
futures = "0.3.13"
1919
bytes = "1.0.1"
20+
cfg-if = "1"
2021

2122
[dependencies.rsocket_rust]
2223
path = "../rsocket"
2324
features = ["frame"]
2425

2526
[dependencies.tokio]
26-
version = "1.0.1"
27+
version = "1.0.3"
2728
default-features = false
2829
features = [ "rt", "rt-multi-thread", "net", "sync", "io-util", "macros" ]
2930

3031
[dependencies.tokio-util]
31-
version = "0.6.1"
32+
version = "0.6.3"
3233
default-features = false
3334
features = ["codec"]
3435

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
mod tcp;
2-
#[cfg(feature = "tls")]
3-
mod tls;
42
mod uds;
53

64
pub use tcp::TcpClientTransport;
7-
#[cfg(feature = "tls")]
8-
pub use tls::TlsClientTransport;
95
pub use uds::UnixClientTransport;
6+
7+
cfg_if! {
8+
if #[cfg(feature = "tls")] {
9+
mod tls;
10+
pub use tls::TlsClientTransport;
11+
}
12+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
mod codec;
22
mod tcp;
3-
#[cfg(feature = "tls")]
4-
mod tls;
53
mod uds;
64

75
pub use tcp::TcpConnection;
8-
#[cfg(feature = "tls")]
9-
pub use tls::TlsConnection;
106
pub use uds::UnixConnection;
7+
8+
cfg_if! {
9+
if #[cfg(feature = "tls")] {
10+
mod tls;
11+
pub use tls::TlsConnection;
12+
}
13+
}

rsocket-transport-tcp/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
#[macro_use]
44
extern crate log;
5+
#[macro_use]
6+
extern crate cfg_if;
57

68
mod client;
79
mod connection;
810
mod misc;
911
mod server;
1012

11-
#[cfg(feature = "tls")]
12-
pub use client::TlsClientTransport;
1313
pub use client::{TcpClientTransport, UnixClientTransport};
14-
#[cfg(feature = "tls")]
15-
pub use connection::TlsConnection;
1614
pub use connection::{TcpConnection, UnixConnection};
17-
#[cfg(feature = "tls")]
18-
pub use server::TlsServerTransport;
1915
pub use server::{TcpServerTransport, UnixServerTransport};
20-
#[cfg(feature = "tls")]
21-
pub use tokio_native_tls;
16+
17+
cfg_if! {
18+
if #[cfg(feature = "tls")] {
19+
pub use tokio_native_tls;
20+
pub use client::TlsClientTransport;
21+
pub use connection::TlsConnection;
22+
pub use server::TlsServerTransport;
23+
}
24+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
mod tcp;
2-
3-
#[cfg(feature = "tls")]
4-
mod tls;
52
mod uds;
63

74
pub use tcp::TcpServerTransport;
8-
#[cfg(feature = "tls")]
9-
pub use tls::TlsServerTransport;
105
pub use uds::UnixServerTransport;
6+
7+
cfg_if! {
8+
if #[cfg(feature = "tls")] {
9+
mod tls;
10+
pub use tls::TlsServerTransport;
11+
}
12+
}

rsocket-transport-wasm/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ description = "WASM Websocket RSocket transport implementation."
1111

1212
[dependencies]
1313
bytes = "1.0.1"
14-
wasm-bindgen-futures = "0.4.19"
15-
futures-channel = "0.3.10"
16-
futures-util = "0.3.10"
17-
js-sys = "0.3.46"
18-
serde = "1.0.119"
19-
serde_derive = "1.0.119"
14+
wasm-bindgen-futures = "0.4.20"
15+
futures-channel = "0.3.13"
16+
futures-util = "0.3.13"
17+
js-sys = "0.3.47"
18+
serde = "1.0.123"
19+
serde_derive = "1.0.123"
2020
async-trait = "0.1.42"
21-
log = "0.4.13"
21+
log = "0.4.14"
2222

2323
[dependencies.rsocket_rust]
2424
path = "../rsocket"
2525
features = ["frame"]
2626

2727
[dependencies.wasm-bindgen]
28-
version = "0.2.69"
28+
version = "0.2.70"
2929
features = ["serde-serialize"]
3030

3131
[dependencies.web-sys]
32-
version = "0.3.46"
32+
version = "0.3.47"
3333
features = [
3434
"FileReader",
3535
"ProgressEvent",

rsocket-transport-websocket/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ homepage = "https://github.com/rsocket/rsocket-rust"
1010
description = "Websocket RSocket transport implementation."
1111

1212
[dependencies]
13-
log = "0.4.13"
14-
futures = "0.3.10"
13+
log = "0.4.14"
14+
futures = "0.3.13"
1515
bytes = "1.0.1"
16-
url = "2.2.0"
16+
url = "2.2.1"
1717
tokio-tungstenite = "0.13.0"
1818

1919
[dependencies.rsocket_rust]
2020
path = "../rsocket"
2121
features = ["frame"]
2222

2323
[dependencies.tokio]
24-
version = "1.0.1"
24+
version = "1.0.3"
2525
default-features = false
2626
features = [ "rt", "rt-multi-thread", "net", "sync"]

rsocket/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ description = "rsocket-rust is an implementation of the RSocket protocol in Rust
1313
log = "0.4.13"
1414
bytes = "1.0.1"
1515
futures = "0.3.10"
16-
lazy_static = "1.4.0"
16+
once_cell = "1.6.0"
1717
async-trait = "0.1.42"
1818
dashmap = "4.0.2"
1919
thiserror = "1.0.23"
2020
anyhow = "1.0.38"
2121
async-stream = "0.3.0"
22+
cfg-if = "1"
2223

2324
[target.'cfg(target_arch = "wasm32")'.dependencies]
2425
wasm-bindgen-futures = "0.4.19"
2526

2627
[dependencies.tokio]
27-
version = "1.0.1"
28+
version = "1.0.3"
2829
default-features = false
2930
features = [ "macros", "rt", "rt-multi-thread", "sync", "time" ]
3031

rsocket/src/extension/mime.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
use std::collections::HashMap;
22
use std::fmt;
33

4+
use once_cell::sync::Lazy;
5+
46
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
57
pub enum MimeType {
68
Normal(String),
79
WellKnown(u8),
810
}
911

10-
lazy_static! {
11-
static ref U8_TO_STR: HashMap<u8, &'static str> = {
12-
let mut m = HashMap::new();
13-
for it in list_all().iter() {
14-
m.insert(it.0, it.1);
15-
}
16-
m
17-
};
18-
static ref STR_TO_U8: HashMap<&'static str, u8> = {
19-
let mut m = HashMap::new();
20-
for it in list_all().iter() {
21-
m.insert(it.1, it.0);
22-
}
23-
m
24-
};
25-
}
12+
static U8_TO_STR: Lazy<HashMap<u8, &'static str>> = Lazy::new(|| {
13+
let mut m = HashMap::new();
14+
for it in list_all().iter() {
15+
m.insert(it.0, it.1);
16+
}
17+
m
18+
});
19+
20+
static STR_TO_U8: Lazy<HashMap<&'static str, u8>> = Lazy::new(|| {
21+
let mut m = HashMap::new();
22+
for it in list_all().iter() {
23+
m.insert(it.1, it.0);
24+
}
25+
m
26+
});
2627

2728
impl MimeType {
2829
pub fn parse(value: u8) -> Option<MimeType> {

rsocket/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,25 @@
9595
pub use async_stream::stream;
9696
/// A re-export of [`async-trait`](https://docs.rs/async-trait) for use with RSocket trait implementation.
9797
pub use async_trait::async_trait;
98+
use cfg_if::cfg_if;
9899

99100
#[macro_use]
100101
extern crate anyhow;
101102
#[macro_use]
102103
extern crate log;
103104
#[macro_use]
104-
extern crate lazy_static;
105+
extern crate cfg_if;
105106

106107
pub mod error;
107108
pub mod extension;
108109

109-
#[cfg(feature = "frame")]
110-
pub mod frame;
111-
#[cfg(not(feature = "frame"))]
112-
mod frame;
110+
cfg_if! {
111+
if #[cfg(feature = "frame")]{
112+
pub mod frame;
113+
}else{
114+
mod frame;
115+
}
116+
}
113117

114118
mod core;
115119
mod payload;

0 commit comments

Comments
 (0)