Skip to content

Commit 689e2df

Browse files
author
Surkov, Kirill
committed
Use cfg_aliases to simplify cfg! expressions
1 parent 9517e70 commit 689e2df

File tree

6 files changed

+40
-217
lines changed

6 files changed

+40
-217
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

identity/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ rmp-serde = "1.3"
4949
criterion = "0.5"
5050
hex-literal = "0.4.1"
5151

52+
[build-dependencies]
53+
cfg_aliases = "0.2.1"
54+
5255
[[bench]]
5356
name = "peer_id"
5457
harness = false

identity/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
cfg_aliases::cfg_aliases! {
3+
rsa_supported: { any(not(target_arch = "wasm32"), target_os = "unknown") }
4+
}
5+
}

identity/src/error.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ impl DecodingError {
7676
}
7777
}
7878

79-
#[cfg(all(
80-
feature = "rsa",
81-
any(
82-
not(target_arch = "wasm32"),
83-
all(target_arch = "wasm32", target_os = "unknown")
84-
)
85-
))]
79+
#[cfg(all(feature = "rsa", rsa_supported))]
8680
pub(crate) fn encoding_unsupported(key_type: &'static str) -> Self {
8781
Self {
8882
msg: format!("encoding {key_type} key to Protobuf is unsupported"),
@@ -112,27 +106,15 @@ pub struct SigningError {
112106

113107
/// An error during encoding of key material.
114108
impl SigningError {
115-
#[cfg(all(
116-
feature = "rsa",
117-
any(
118-
not(target_arch = "wasm32"),
119-
all(target_arch = "wasm32", target_os = "unknown")
120-
)
121-
))]
109+
#[cfg(all(feature = "rsa", rsa_supported))]
122110
pub(crate) fn new<S: ToString>(msg: S) -> Self {
123111
Self {
124112
msg: msg.to_string(),
125113
source: None,
126114
}
127115
}
128116

129-
#[cfg(all(
130-
feature = "rsa",
131-
any(
132-
not(target_arch = "wasm32"),
133-
all(target_arch = "wasm32", target_os = "unknown")
134-
)
135-
))]
117+
#[cfg(all(feature = "rsa", rsa_supported))]
136118
pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self {
137119
Self {
138120
source: Some(Box::new(source)),

0 commit comments

Comments
 (0)