Skip to content

Commit

Permalink
BREAKING: cargo: simplify crate features
Browse files Browse the repository at this point in the history
This gets rid of the 'serde1-{std,alloc,core}' features and just
replaces it with a single proper 'serde' feature. We make it work as one
would expect with the other crate features by using the new 'dep:' and
'pkg?' Cargo.toml feature syntax.

This is a breaking change because the 'serde1' features no longer exist.
Instead, you just need to enable the 'serde' feature and it should
automatically do the right thing depending on whether you also have
'std', 'alloc' or neither set.

Ref: https://doc.rust-lang.org/cargo/reference/features.html
Ref: #40 (comment)
  • Loading branch information
BurntSushi committed Sep 2, 2022
1 parent 7a4782a commit 4133e76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ jobs:
# We run a few other builds, but only on one instance to avoid doing
# more work than we need to.
- if: matrix.build == 'stable'
run: cargo build --verbose --features serde1-std
run: cargo build --verbose --features serde
- if: matrix.build == 'stable'
run: cargo build --verbose --no-default-features
- if: matrix.build == 'stable'
run: cargo build --verbose --no-default-features --features serde1-alloc
run: cargo build --verbose --no-default-features --features serde,alloc
- if: matrix.build == 'stable'
run: cargo build --verbose --no-default-features --features serde1-core
run: cargo build --verbose --no-default-features --features serde
- if: matrix.build == 'stable'
run: cargo build --verbose --no-default-features --features alloc
# Our dev dependencies evolve more rapidly than we'd like, so only run
Expand All @@ -67,19 +67,17 @@ jobs:
# combinations, but just on 'stable' to avoid doing more work that we have
# to.
- if: matrix.build == 'stable'
run: cargo test --verbose --features serde1-std
run: cargo test --verbose --features serde
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features --features serde1-alloc
run: cargo test --verbose --no-default-features --features serde,alloc
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features --features serde1-core
run: cargo test --verbose --no-default-features --features serde
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features --features alloc
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features --features alloc,unicode
- if: matrix.build == 'stable'
run: cargo test --verbose --no-default-features --features unicode,serde1-alloc
- name: Run benchmarks as tests
if: matrix.build == 'stable'
working-directory: ./bench
Expand Down
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ bench = false

[features]
default = ["std", "unicode"]
std = ["alloc", "memchr/std"]
alloc = []
unicode = ["lazy_static", "regex-automata"]
serde1-std = ["std", "serde1-alloc", "serde/std"]
serde1-alloc = ["alloc", "serde1-core", "serde/alloc"]
serde1-core = ["serde"]
std = ["alloc", "memchr/std", "serde?/std"]
alloc = ["serde?/alloc"]
unicode = ["dep:lazy_static", "dep:regex-automata"]
serde = ["dep:serde"]

[dependencies]
memchr = { version = "2.4.0", default-features = false }
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,8 @@ and Unicode support.
Unicode data compiled into the binary. This includes, but is not limited to,
grapheme/word/sentence segmenters. When this is disabled, basic support such
as UTF-8 decoding is still included.
* `serde1-std` - **Disabled** by default. Enables implementations of serde
traits for the `BStr` and `BString` types. This also enables the `std` and
`serde/std` features.
* `serde1-alloc` - **Disabled** by default. Enables implementations of serde
traits for the `BStr` and `BString` types, but without enabling `serde/std`.
Instead, `serde/alloc` is enabled. This also enables the `alloc` feature.
* `serde1-core` - **Disabled** by default. Enables implementations of serde
traits for the `BStr` type only, intended for use without `std` or `alloc`.
Generally, you want at most one of `serde1-std`, `serde1-alloc` or
`serde1-core`, but not more than one.
* `serde` - Enables implementations of serde traits for `BStr`, and also
`BString` when `alloc` is enabled.


### Minimum Rust version policy
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@ UTF-8, and thus contain latent bugs on Unix where paths with invalid UTF-8 are
not terribly uncommon. If you instead use byte strings, then you're guaranteed
to write correct code for Unix, at the cost of getting a corner case wrong on
Windows.
# Cargo features
This crates comes with a few features that control standard library, serde
and Unicode support.
* `std` - **Enabled** by default. This provides APIs that require the standard
library, such as `Vec<u8>` and `PathBuf`. Enabling this feature also enables
the `alloc` feature and any other relevant `std` features for dependencies.
* `alloc` - **Enabled** by default. This provides APIs that require allocations
via the `alloc` crate, such as `Vec<u8>`.
* `unicode` - **Enabled** by default. This provides APIs that require sizable
Unicode data compiled into the binary. This includes, but is not limited to,
grapheme/word/sentence segmenters. When this is disabled, basic support such
as UTF-8 decoding is still included.
* `serde` - Enables implementations of serde traits for `BStr`, and also
`BString` when `alloc` is enabled.
*/

#![cfg_attr(not(any(feature = "std", test)), no_std)]
Expand Down

0 comments on commit 4133e76

Please sign in to comment.