From bf68c634f9667ac198a410d7d13d66a3a71dcc89 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Wed, 11 Dec 2024 23:19:36 +0800 Subject: [PATCH 01/10] bump version to 1.2.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 83fa417..7467491 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ exclude = ["examples"] authors = [ "aarkegz " ] license = "MIT" edition = "2021" -version = "1.1.0" +version = "1.2.0-dev" repository = "https://github.com/GeminiLab/enumerable/" include = [ "README.md", @@ -33,4 +33,4 @@ std = ["enumerable_derive/std"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -enumerable_derive = { path = "enumerable_derive", version = "=1.1.0" } +enumerable_derive = { path = "enumerable_derive", version = "=1.2.0-dev" } From 4ba7e8862977b92c6cf9e1843111729a5bd1f3fb Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 20:30:51 +0800 Subject: [PATCH 02/10] introduce explicit "no_std" to avoid compiler errors on targets without "std" --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 160619d..154b3e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("./CRATE_DOC.md")] /// `Enumerable` is a trait for types that can have their possible values enumerated. From c38dbb75a222a7ad5991231231812d1549384520 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 20:31:08 +0800 Subject: [PATCH 03/10] add a section in ci test --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2438d88..3d02cb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,17 @@ jobs: - run: ./examples/run_examples.sh - run: ./examples/example_crates/run_example_crates.sh + multi_targets_build: + name: multi-targets build + runs-on: ubuntu-latest + strategy: + matrix: + target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-unknown-none, aarch64-unknown-none-softfloat] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo build --target ${{ matrix.target }} --all-features + rustfmt-check: name: rustfmt check runs-on: ubuntu-latest From 873030ae14af1448ca9753463b7df694effee487 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 20:55:29 +0800 Subject: [PATCH 04/10] fix tests --- .github/workflows/ci.yml | 10 +++++++++- examples/example_crates/no_std/Cargo.toml | 5 +++++ examples/example_crates/no_std/src/main.rs | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d02cb4..5874b31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,18 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-unknown-none, aarch64-unknown-none-softfloat] + target: + - x86_64-unknown-linux-gnu + - x86_64-unknown-none + - aarch64-unknown-linux-gnu + - aarch64-unknown-none-softfloat + - riscv64gc-unknown-none-softfloat + - riscv64imac-unknown-none-softfloat steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} - run: cargo build --target ${{ matrix.target }} --all-features rustfmt-check: diff --git a/examples/example_crates/no_std/Cargo.toml b/examples/example_crates/no_std/Cargo.toml index 3611bc2..2b9acaa 100644 --- a/examples/example_crates/no_std/Cargo.toml +++ b/examples/example_crates/no_std/Cargo.toml @@ -9,3 +9,8 @@ version = "0.1.0" [dependencies] enumerable = { path = "../../../", default-features = false } + +[profile] +dev.panic = "abort" +release.panic = "abort" + diff --git a/examples/example_crates/no_std/src/main.rs b/examples/example_crates/no_std/src/main.rs index 534d6c8..54e6861 100644 --- a/examples/example_crates/no_std/src/main.rs +++ b/examples/example_crates/no_std/src/main.rs @@ -1,6 +1,6 @@ //! This example tests the `Enumerable` derive macro in a `no_std` environment. - -#![no_std] +//! +//! This example itself is not `no_std`, but it uses the `enumerable` crate with `default-features = false`. use enumerable::Enumerable; From df7ac056e2a8551e61c98aa84a6f65b4fa00082e Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 20:59:03 +0800 Subject: [PATCH 05/10] fix "multi-targets-no-std" ci test --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5874b31..2d53510 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,8 @@ jobs: - run: ./examples/run_examples.sh - run: ./examples/example_crates/run_example_crates.sh - multi_targets_build: - name: multi-targets build + multi-targets-no-std: + name: multi-targets no_std runs-on: ubuntu-latest strategy: matrix: @@ -29,7 +29,8 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - - run: cargo build --target ${{ matrix.target }} --all-features + components: rustc, cargo + - run: cargo build --target ${{ matrix.target }} --no-default-features rustfmt-check: name: rustfmt check From 6fcca6249e86e29358fe3fb449729e3d53d206d2 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 21:06:36 +0800 Subject: [PATCH 06/10] fix target names for riscv targets --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d53510..779b7de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,8 @@ jobs: - x86_64-unknown-none - aarch64-unknown-linux-gnu - aarch64-unknown-none-softfloat - - riscv64gc-unknown-none-softfloat - - riscv64imac-unknown-none-softfloat + - riscv64gc-unknown-none-elf + - riscv64imac-unknown-none-elf steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable From 060e75287622eeb50f47c6d4163da949442002ae Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 21:13:19 +0800 Subject: [PATCH 07/10] add `size_hint` for `OptionEnumerator` --- src/impl_built_in.rs | 14 ++++++++++++++ src/test/mod.rs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/impl_built_in.rs b/src/impl_built_in.rs index bd50cab..fe6b610 100644 --- a/src/impl_built_in.rs +++ b/src/impl_built_in.rs @@ -111,6 +111,20 @@ where self.inner.next().map(Some) } } + + /// Returns the lower and upper bound of the iterator. + fn size_hint(&self) -> (usize, Option) { + let (lower, upper) = self.inner.size_hint(); + + if self.first { + ( + lower.saturating_add(1), + upper.and_then(|u| u.checked_add(1)), + ) + } else { + (lower, upper) + } + } } /// This is an implementation of the `Enumerable` trait for `Option` where `T` is `Enumerable`. diff --git a/src/test/mod.rs b/src/test/mod.rs index 297bb8f..63093ef 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -16,7 +16,7 @@ mod primitive { #[test] fn test_option_bool() { - assert_enumerator_eq(vec![None, Some(false), Some(true)]); + assert_enumerator_eq_with_size_hint(vec![None, Some(false), Some(true)]); } #[test] From 31666a917a781d7ef3c1479c0dfaed8c0523bd15 Mon Sep 17 00:00:00 2001 From: Su Mingxian Date: Sat, 12 Jul 2025 21:14:53 +0800 Subject: [PATCH 08/10] more detailed doc for `::size_hint` Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/impl_built_in.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/impl_built_in.rs b/src/impl_built_in.rs index fe6b610..1d4d156 100644 --- a/src/impl_built_in.rs +++ b/src/impl_built_in.rs @@ -112,7 +112,13 @@ where } } - /// Returns the lower and upper bound of the iterator. + /// Implements the standard library's `Iterator::size_hint` method. + /// + /// This method returns the lower and upper bound of the iterator. For `OptionEnumerator`, + /// the bounds are adjusted to account for the `None` variant: + /// - If `self.first` is `true`, the lower bound is incremented by 1, and the upper bound + /// is incremented by 1 (if it exists), to include the `None` variant. + /// - Otherwise, the bounds are directly derived from the inner enumerator. fn size_hint(&self) -> (usize, Option) { let (lower, upper) = self.inner.size_hint(); From 82c018f7a91fdd6e95142f8505736da2596621c6 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 21:16:01 +0800 Subject: [PATCH 09/10] reformatted --- src/impl_built_in.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_built_in.rs b/src/impl_built_in.rs index 1d4d156..1bfcb46 100644 --- a/src/impl_built_in.rs +++ b/src/impl_built_in.rs @@ -113,7 +113,7 @@ where } /// Implements the standard library's `Iterator::size_hint` method. - /// + /// /// This method returns the lower and upper bound of the iterator. For `OptionEnumerator`, /// the bounds are adjusted to account for the `None` variant: /// - If `self.first` is `true`, the lower bound is incremented by 1, and the upper bound From 26904d58d7eb95070ba5af825e6d2903cda19c55 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 21:20:53 +0800 Subject: [PATCH 10/10] release version 1.2.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7467491..56467e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ exclude = ["examples"] authors = [ "aarkegz " ] license = "MIT" edition = "2021" -version = "1.2.0-dev" +version = "1.2.0" repository = "https://github.com/GeminiLab/enumerable/" include = [ "README.md", @@ -33,4 +33,4 @@ std = ["enumerable_derive/std"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -enumerable_derive = { path = "enumerable_derive", version = "=1.2.0-dev" } +enumerable_derive = { path = "enumerable_derive", version = "=1.2.0" }