Skip to content

Commit 55e08ca

Browse files
committed
Add a feature for each bit-width
Fixes #97
1 parent 978bc8c commit 55e08ca

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

lib/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.6.0
4+
5+
### Minor
6+
7+
- Add `base2`, `base4`, `base8`, `base16`, `base32`, and `base64` features
8+
39
## 2.5.0
410

511
### Minor

lib/Cargo.toml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding"
3-
version = "2.5.0"
3+
version = "2.6.0"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -18,6 +18,17 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
1818
rustdoc-args = ["--cfg=docsrs"]
1919

2020
[features]
21-
default = ["std"]
21+
# All features are enabled by default. Because of how cargo works, if you want to disable features,
22+
# you have to disable all of them, then enable back those you need. For example:
23+
# - To disable "std", you need to enable ["alloc", "all"].
24+
# - To disable all bases but base32 and base64, you need to enable ["std", "base32", "base64"].
25+
default = ["std", "all"]
2226
alloc = []
2327
std = ["alloc"]
28+
all = ["base2", "base4", "base8", "base16", "base32", "base64"]
29+
base2 = []
30+
base4 = []
31+
base8 = []
32+
base16 = []
33+
base32 = []
34+
base64 = []

lib/macro/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding-macro"
3-
version = "0.1.14"
3+
version = "0.1.15"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -14,5 +14,5 @@ description = "Macros for data-encoding"
1414
include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
1515

1616
[dependencies]
17-
data-encoding = { version = "2.5.0", path = "..", default-features = false }
18-
data-encoding-macro-internal = { version = "0.1.12", path = "internal" }
17+
data-encoding = { version = "2.6.0", path = "..", default-features = false, features = ["all"] }
18+
data-encoding-macro-internal = { version = "0.1.13", path = "internal" }

lib/macro/internal/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "data-encoding-macro-internal"
3-
version = "0.1.12"
3+
version = "0.1.13"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -14,10 +14,10 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
1414
proc-macro = true
1515

1616
[dependencies.data-encoding]
17-
version = "2.5.0"
17+
version = "2.6.0"
1818
path = "../.."
1919
default-features = false
20-
features = ["alloc"]
20+
features = ["alloc", "all"]
2121

2222
[dependencies.syn]
2323
version = "1"

lib/src/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,17 @@ macro_rules! define {
202202

203203
define!(Bf: bool = false);
204204
define!(Bt: bool = true);
205+
#[cfg(feature = "base2")]
205206
define!(N1: usize = 1);
207+
#[cfg(feature = "base4")]
206208
define!(N2: usize = 2);
209+
#[cfg(feature = "base8")]
207210
define!(N3: usize = 3);
211+
#[cfg(feature = "base16")]
208212
define!(N4: usize = 4);
213+
#[cfg(feature = "base32")]
209214
define!(N5: usize = 5);
215+
#[cfg(feature = "base64")]
210216
define!(N6: usize = 6);
211217

212218
#[derive(Copy, Clone)]
@@ -237,13 +243,19 @@ macro_rules! dispatch {
237243
};
238244
(let $var: ident: usize = $val: expr; $($body: tt)*) => {
239245
match $val {
246+
#[cfg(feature = "base2")]
240247
1 => { let $var = N1; dispatch!($($body)*) },
248+
#[cfg(feature = "base4")]
241249
2 => { let $var = N2; dispatch!($($body)*) },
250+
#[cfg(feature = "base8")]
242251
3 => { let $var = N3; dispatch!($($body)*) },
252+
#[cfg(feature = "base16")]
243253
4 => { let $var = N4; dispatch!($($body)*) },
254+
#[cfg(feature = "base32")]
244255
5 => { let $var = N5; dispatch!($($body)*) },
256+
#[cfg(feature = "base64")]
245257
6 => { let $var = N6; dispatch!($($body)*) },
246-
_ => panic!(),
258+
x => panic!("feature base{} is disabled", 1 << x),
247259
}
248260
};
249261
(let $var: ident: Option<$type: ty> = $val: expr; $($body: tt)*) => {

xtask/src/main.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ impl Action {
137137
instructions *= &[&["--release"]];
138138
}
139139
let features: &[&[&str]] = match self.dir {
140-
Dir::Lib => {
141-
&[&["--no-default-features", "--features=alloc"], &["--no-default-features"]]
142-
}
140+
Dir::Lib => &[
141+
&["--no-default-features", "--features=alloc,all"],
142+
&["--no-default-features", "--features=all"],
143+
&["--no-default-features", "--features=base2"],
144+
&["--no-default-features", "--features=base4"],
145+
&["--no-default-features", "--features=base8"],
146+
&["--no-default-features", "--features=base16"],
147+
&["--no-default-features", "--features=base32"],
148+
&["--no-default-features", "--features=base64"],
149+
],
143150
_ => &[],
144151
};
145152
instructions *= features;

0 commit comments

Comments
 (0)