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

0.2.34 release #61

Merged
merged 9 commits into from
Dec 6, 2024
Merged
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
35 changes: 26 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
rust: [stable, beta, nightly, 1.57.0, 1.64.0]
rust: [stable, beta, nightly, 1.57.0, 1.64.0, 1.83.0]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -41,14 +41,11 @@ jobs:

- uses: actions/checkout@v2
- name: ci-nighly
if: ${{ matrix.rust == 'nightly' && runner.os == 'Linux' }}
if: ${{ matrix.rust != '1.57.0' && matrix.rust != '1.64.0' }}
run: |
rustup override set ${{ matrix.rust }}

cargo update -Z minimal-versions

cd "${{github.workspace}}/const_format_proc_macros/"
cargo test
cargo update

cd "${{github.workspace}}/const_format/"

Expand All @@ -59,10 +56,25 @@ jobs:
cargo test --features "__test assertc"
cargo test --features "__test derive"
cargo test --features "__test constant_time_as_str"
cargo test --features "__test rust_1_64"
cargo test --features "__test rust_1_83"
cargo test --features "__test derive constant_time_as_str"
cargo test --features "__test derive constant_time_as_str assertc"
cargo test --features "__test derive constant_time_as_str assertc more_str_macros rust_1_64"
cargo test --features "__test derive constant_time_as_str assertc more_str_macros rust_1_83"

- uses: actions/checkout@v2
- name: ci-nighly
if: ${{ matrix.rust == 'nightly' && runner.os == 'Linux' }}
run: |
rustup override set ${{ matrix.rust }}

cargo update -Z minimal-versions

cd "${{github.workspace}}/const_format_proc_macros/"
cargo test

cd "${{github.workspace}}/const_format/"

cargo test --features "__inline_const_pat_tests derive constant_time_as_str assertc more_str_macros rust_1_83"

MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-check-number-validity -Zmiri-symbolic-alignment-check"
Expand All @@ -76,5 +88,10 @@ jobs:

cargo clean

# tests the crate without the constant_time_as_str feature
# (and also without any feature that implies it)
cargo miri test --tests --features "__test derive fmt assertc"
cargo miri test --features "__test derive fmt constant_time_as_str assertc"

# tests the crate with every feature, including constant_time_as_str
cargo miri test \
--features "__inline_const_pat_tests derive constant_time_as_str assertc more_str_macros rust_1_83"
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ members=[
"print_errors",
"print_warnings",
]
resolver = "2"
23 changes: 23 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ This is the changelog,summarising changes in each version(some minor changes may

# 0.2

### 0.2.34

Now all features that used to require nightly only require Rust 1.83.0

Added `"rust_1_83"` feature that enables `"rust_1_64"` feature

Changed `"fmt"` feature to enable `"rust_1_83"` feature

Made many macros forward compatible with inline const patterns(when the `"rust_1_83"` feature is enabled):
- `concatc`
- `concatcp`
- `formatc`
- `formatcp`
- `map_ascii_case`
- `str_get`
- `str_index`
- `str_repeat`
- `str_replace`

Added these macros:
- `str_splice_out`
- `str_split_alt`

### 0.2.33

Fixed Rust Analyzer style warning for assertion macros.
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ This crate provides types and macros for formatting strings at compile-time.

# Rust versions

There are some features that require a variety of stable Rust versions and
others that require Rust nightly,
There are some features that require a variety of Rust versions,
the sections below describe the features that are available for each version.

### Rust 1.57.0
Expand Down Expand Up @@ -60,12 +59,11 @@ The `"rust_1_64"` feature enables these macros:

- [`str_split`]: splits a string constant

### Rust nightly
### Rust 1.83.0

By enabling the "fmt" feature, you can use a [`std::fmt`]-like API.

This requires the nightly compiler, because it uses mutable references in const fn,
which have not been stabilized as of writing these docs.
This requires Rust 1.83.0, because it uses mutable references in const fn.

All the other features of this crate are implemented on top of the [`const_format::fmt`] API:

Expand Down Expand Up @@ -121,11 +119,9 @@ const fn compute_age(s: &str) -> usize { s.len() * 6 }
This example demonstrates how you can use the [`ConstDebug`] derive macro,
and then format the type into a `&'static str` constant.

This example requires Rust nightly, and the `"derive"` feature.
This example requires Rust 1.83.0, and the `"derive"` feature.

```rust
#![feature(const_mut_refs)]

use const_format::{ConstDebug, formatc};

#[derive(ConstDebug)]
Expand Down Expand Up @@ -251,15 +247,15 @@ cfmt = {version = "0.*", package = "const_format"}

# Cargo features

- `"fmt"`: Enables the [`std::fmt`]-like API,
requires Rust nightly because it uses mutable references in const fn.<br>
- `"fmt"`: Enables the [`std::fmt`]-like API and `"rust_1_83"` feature,
requires Rust 1.83.0 because it uses mutable references in const fn.<br>
This feature includes the [`formatc`]/[`writec`] formatting macros.

- `"derive"`: requires Rust nightly, implies the `"fmt"` feature,
- `"derive"`: requires Rust 1.83.0, implies the `"fmt"` feature,
provides the [`ConstDebug`] derive macro to format user-defined types at compile-time.<br>
This implicitly uses the `syn` crate, so clean compiles take a bit longer than without the feature.

- `"assertc"`: requires Rust nightly, implies the `"fmt"` feature,
- `"assertc"`: requires Rust 1.83.0, implies the `"fmt"` feature,
enables the [`assertc`], [`assertc_eq`], and [`assertc_ne`] assertion macros.<br>
This feature was previously named `"assert"`,
but it was renamed to avoid confusion with the `"assertcp"` feature.
Expand All @@ -271,6 +267,9 @@ Enables the [`assertcp`], [`assertcp_eq`], and [`assertcp_ne`] assertion macros.
Allows the `as_bytes_alt` methods and `slice_up_to_len_alt` methods to run
in constant time, rather than linear time (proportional to the truncated part of the slice).

- `"rust_1_83"`: Enables the `"rust_1_64"` feature
and makes macros that evaluate to a value compatible with [inline const patterns].

# No-std support

`const_format` is unconditionally `#![no_std]`, it can be used anywhere Rust can be used.
Expand Down Expand Up @@ -339,3 +338,5 @@ need to be explicitly enabled with cargo features.
[`str_split`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_split.html

[`str::replace`]: https://doc.rust-lang.org/std/primitive.str.html#method.replace

[inline const patterns]: https://doc.rust-lang.org/1.83.0/unstable-book/language-features/inline-const-pat.html
12 changes: 7 additions & 5 deletions const_format/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "const_format"
version = "0.2.33"
version = "0.2.34"
authors = ["rodrimati1992 <[email protected]>"]
rust-version = "1.57.0"
edition = "2021"
Expand All @@ -24,7 +24,8 @@ const_generics = ["rust_1_51"]
nightly_const_generics = ["const_generics"]
rust_1_51 = []
rust_1_64 = ["rust_1_51", "konst", "konst/rust_1_64"]
fmt = ["rust_1_64"]
rust_1_83 = ["rust_1_64"]
fmt = ["rust_1_83"]
derive = ["fmt", "const_format_proc_macros/derive"]

# soft-deprecated, use assertc instead.
Expand All @@ -50,10 +51,11 @@ all = [
__debug = ["const_format_proc_macros/debug"]
__test = []
__only_new_tests = ["__test"]
__inline_const_pat_tests = ["__test", "fmt"]
__docsrs = []

[dependencies.const_format_proc_macros]
version = "=0.2.33"
version = "=0.2.34"
path = "../const_format_proc_macros"

[dependencies.konst]
Expand All @@ -62,8 +64,8 @@ default-features = false
optional = true

[dev-dependencies]
fastrand = {version = "1.3.5", default_features = false}
arrayvec = {version = "0.5.1", default_features = false}
fastrand = {version = "1.3.5", default-features = false}
arrayvec = {version = "0.5.1", default-features = false}

[package.metadata.docs.rs]
features = ["all", "__docsrs"]
Expand Down
6 changes: 1 addition & 5 deletions const_format/src/__str_methods/str_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ impl SplitInput {
}
}

pub const fn count_splits(
SplitInput {
mut str, pattern, ..
}: SplitInput,
) -> usize {
pub const fn count_splits(SplitInput { str, pattern, .. }: SplitInput) -> usize {
let mut count = 1;

match pattern.normalize() {
Expand Down
10 changes: 1 addition & 9 deletions const_format/src/const_debug_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
/// # Features
///
/// This derive macro is only available with the "derive" feature,
/// and the nightly compiler,
/// because at the time of writing these docs (2023-10-XX) mutable references in const fn
/// require the unstable
/// [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349) feature.
/// and Rust 1.83.0, because is uses mutable references in const.
///
/// # Limitations
///
Expand Down Expand Up @@ -55,7 +52,6 @@
/// Example:
///
/// ```rust
/// # #![feature(const_mut_refs)]
/// #[derive(const_format::ConstDebug)]
/// #[cdeb(impls(
/// "Foo<u8, u64>",
Expand Down Expand Up @@ -153,7 +149,6 @@
/// This example demonstrates using the derive without using any helper attributes.
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// use const_format::{ConstDebug, formatc};
///
Expand Down Expand Up @@ -201,7 +196,6 @@
/// specifying a list of impls of types that unconditionally implement const debug formatting
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// use const_format::{ConstDebug, formatc};
///
Expand Down Expand Up @@ -238,7 +232,6 @@
/// This example demonstrates when you would use the `is_a` attributes.
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// use const_format::{ConstDebug, formatc};
///
Expand Down Expand Up @@ -331,7 +324,6 @@
/// crate is renamed.
///
/// ```rust
/// #![feature(const_mut_refs)]
/// # extern crate self as const_format;
/// # extern crate const_format as cfmt;
/// # fn main() {
Expand Down
12 changes: 0 additions & 12 deletions const_format/src/doctests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub struct ImplFmtWhereClause;

///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// #[derive(const_format::ConstDebug)]
/// struct Foo<T>(*const T)
Expand All @@ -56,7 +55,6 @@ pub struct ImplFmtWhereClause;
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// #[derive(const_format::ConstDebug)]
/// struct Foo<T>(*const T)
Expand All @@ -69,7 +67,6 @@ pub struct ImplFmtWhereClause;
pub struct ConstDebugWhereClause;

/// ```rust
/// #![feature(const_mut_refs)]
///
/// use const_format::StrWriterMut;
///
Expand All @@ -85,7 +82,6 @@ pub struct ConstDebugWhereClause;
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// use const_format::StrWriterMut;
///
Expand All @@ -104,14 +100,12 @@ pub struct ConstDebugWhereClause;
pub struct AsStr_For_StrWriterMut_NoEncoding;

/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc!(true, "foo");
///
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc!(false, "foo");
///
Expand All @@ -120,7 +114,6 @@ pub struct AsStr_For_StrWriterMut_NoEncoding;
/// # With a Formatting argument
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc!(
/// true,
Expand All @@ -139,7 +132,6 @@ pub struct AsStr_For_StrWriterMut_NoEncoding;
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc!(
/// false,
Expand All @@ -163,14 +155,12 @@ pub struct Assert;
/// # assert_eq
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_eq!(0u8, 0u8, "foo");
///
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_eq!(0u8, 10u8, "foo");
///
Expand All @@ -179,14 +169,12 @@ pub struct Assert;
/// # assert_ne
///
/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_ne!(0u8, 10u8, "foo");
///
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_ne!(0u8, 0u8, "foo");
///
Expand Down
Loading
Loading