Skip to content

Commit

Permalink
Remove bytes feature, make concat_bytes! always available
Browse files Browse the repository at this point in the history
This feature was only really required for controlling how the tests were
compiled. It shouldn't be public API. The macro is always available but
the `feature(concat_bytes)` is required to use it without compiler
errors. This change makes the `bytes` feature private API (now `_bytes`)
and only uses it in tests.
  • Loading branch information
rossmacarthur committed Nov 3, 2023
1 parent f369bba commit b7311dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ jobs:
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy --workspace --no-default-features
run: cargo clippy --workspace --all-targets

- name: Test (no default features)
run: cargo test --workspace --no-default-features --lib --test '*'
- name: Test
if: matrix.toolchain != 'nightly'
run: cargo test --workspace

- name: Test
if: matrix.toolchain == 'nightly'
run: cargo test --workspace
run: cargo test --workspace --features _bytes
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ keywords = ["concat", "const"]
categories = ["no-std", "rust-patterns"]

[features]
default = ["bytes"]

# Adds support for the concat_bytes! macro
bytes = []
# Private API: compiles the tests for the concat_bytes! macro
_bytes = []
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,30 @@ macro_rules! _maybe_std_concat {
/// This macro takes any number of comma-separated literals or constant
/// expressions and yields an expression of type [`&'static [u8]`][slice] which
/// represents all of the literals and expressions concatenated left-to-right.
/// Literals are converted using [`core::concat_bytes!`] and then each
/// expression is concatenated using [`concat_slices!`].
/// Literals are converted using [`std::concat_bytes!`] and then each expression
/// is concatenated using [`concat_slices!`].
///
/// See the [crate documentation][crate] for examples.
///
/// # Stability note
///
/// 🔬 This macro uses a nightly-only experimental API, [`core::concat_bytes`],
/// 🔬 This macro uses a nightly-only experimental API, [`std::concat_bytes!`],
/// for processing byte literals, until it is stabilized you will need to add
/// the following to the root of your crate.
///
/// ```
/// ```text
/// #![feature(concat_bytes)]
/// ```
///
/// # Differences to `std`
///
/// Unlike the standard library macro this macro does not accept byte array
/// literals directly like `[b'A', 32, b'B']` instead you have to pass a slice
/// like `&[b'A', 32, b'B']`.
///
/// [`std::concat!`]: core::concat
/// [`std::concat_bytes!`]: core::concat_bytes
#[macro_export]
#[cfg(feature = "bytes")]
macro_rules! concat_bytes {
($($e:expr),* $(,)?) => {{
$crate::_concat_bytes!($($e),*)
Expand All @@ -145,7 +149,6 @@ macro_rules! concat_bytes {

#[doc(hidden)]
#[macro_export]
#[cfg(feature = "bytes")]
macro_rules! _concat_bytes {
() => { b"" };

Expand All @@ -160,7 +163,6 @@ macro_rules! _concat_bytes {

#[doc(hidden)]
#[macro_export]
#[cfg(feature = "bytes")]
macro_rules! _maybe_std_concat_bytes {
($e:literal) => {
$crate::core::concat_bytes!($e)
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "bytes", feature(concat_bytes))]
#![cfg_attr(feature = "_bytes", feature(concat_bytes))]

#[test]
fn concat_smoke() {
Expand Down Expand Up @@ -30,7 +30,7 @@ fn concat_smoke() {
}

#[test]
#[cfg(feature = "bytes")]
#[cfg(feature = "_bytes")]
fn concat_bytes_smoke() {
use constcat::concat_bytes;

Expand Down

0 comments on commit b7311dc

Please sign in to comment.