Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature for each bit-width #101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.6.0

### Minor

- Add `base2`, `base4`, `base8`, `base16`, `base32`, and `base64` features

## 2.5.0

### Minor
Expand Down
15 changes: 13 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding"
version = "2.5.0"
version = "2.6.0"
authors = ["Julien Cretin <git@ia0.eu>"]
license = "MIT"
edition = "2018"
Expand All @@ -18,6 +18,17 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
rustdoc-args = ["--cfg=docsrs"]

[features]
default = ["std"]
# All features are enabled by default. Because of how cargo works, if you want to disable features,
# you have to disable all of them, then enable back those you need. For example:
# - To disable "std", you need to enable ["alloc", "all"].
# - To disable all bases but base32 and base64, you need to enable ["std", "base32", "base64"].
default = ["std", "all"]
alloc = []
std = ["alloc"]
all = ["base2", "base4", "base8", "base16", "base32", "base64"]
base2 = []
base4 = []
base8 = []
base16 = []
base32 = []
base64 = []
6 changes: 3 additions & 3 deletions lib/macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding-macro"
version = "0.1.14"
version = "0.1.15"
authors = ["Julien Cretin <cretin@google.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -14,5 +14,5 @@ description = "Macros for data-encoding"
include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]

[dependencies]
data-encoding = { version = "2.5.0", path = "..", default-features = false }
data-encoding-macro-internal = { version = "0.1.12", path = "internal" }
data-encoding = { version = "2.6.0", path = "..", default-features = false, features = ["all"] }
data-encoding-macro-internal = { version = "0.1.13", path = "internal" }
6 changes: 3 additions & 3 deletions lib/macro/internal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-encoding-macro-internal"
version = "0.1.12"
version = "0.1.13"
authors = ["Julien Cretin <cretin@google.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -14,10 +14,10 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"]
proc-macro = true

[dependencies.data-encoding]
version = "2.5.0"
version = "2.6.0"
path = "../.."
default-features = false
features = ["alloc"]
features = ["alloc", "all"]

[dependencies.syn]
version = "1"
Expand Down
14 changes: 13 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ macro_rules! define {

define!(Bf: bool = false);
define!(Bt: bool = true);
#[cfg(feature = "base2")]
define!(N1: usize = 1);
#[cfg(feature = "base4")]
define!(N2: usize = 2);
#[cfg(feature = "base8")]
define!(N3: usize = 3);
#[cfg(feature = "base16")]
define!(N4: usize = 4);
#[cfg(feature = "base32")]
define!(N5: usize = 5);
#[cfg(feature = "base64")]
define!(N6: usize = 6);

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -237,13 +243,19 @@ macro_rules! dispatch {
};
(let $var: ident: usize = $val: expr; $($body: tt)*) => {
match $val {
#[cfg(feature = "base2")]
1 => { let $var = N1; dispatch!($($body)*) },
#[cfg(feature = "base4")]
2 => { let $var = N2; dispatch!($($body)*) },
#[cfg(feature = "base8")]
3 => { let $var = N3; dispatch!($($body)*) },
#[cfg(feature = "base16")]
4 => { let $var = N4; dispatch!($($body)*) },
#[cfg(feature = "base32")]
5 => { let $var = N5; dispatch!($($body)*) },
#[cfg(feature = "base64")]
6 => { let $var = N6; dispatch!($($body)*) },
_ => panic!(),
x => panic!("feature base{} is disabled", 1 << x),
}
};
(let $var: ident: Option<$type: ty> = $val: expr; $($body: tt)*) => {
Expand Down
13 changes: 10 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@ impl Action {
instructions *= &[&["--release"]];
}
let features: &[&[&str]] = match self.dir {
Dir::Lib => {
&[&["--no-default-features", "--features=alloc"], &["--no-default-features"]]
}
Dir::Lib => &[
&["--no-default-features", "--features=alloc,all"],
&["--no-default-features", "--features=all"],
&["--no-default-features", "--features=base2"],
&["--no-default-features", "--features=base4"],
&["--no-default-features", "--features=base8"],
&["--no-default-features", "--features=base16"],
&["--no-default-features", "--features=base32"],
&["--no-default-features", "--features=base64"],
],
_ => &[],
};
instructions *= features;
Expand Down