From ce66433fa1462250fcd7582a7e04c7872604f835 Mon Sep 17 00:00:00 2001 From: winstonallo Date: Thu, 25 Sep 2025 18:16:12 +0200 Subject: [PATCH 1/4] Return &mut Self from setters to allow for function chaining --- macros/src/generator.rs | 3 ++- src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/macros/src/generator.rs b/macros/src/generator.rs index 4f5c700..575cfe0 100644 --- a/macros/src/generator.rs +++ b/macros/src/generator.rs @@ -33,8 +33,9 @@ pub fn expand_bitmap(input: BitmapInput) -> syn::Result { (self.0 >> #index) & #mask } - pub fn #setter_name(&mut self, val: u8) { + pub fn #setter_name(&mut self, val: u8) -> &mut Self { self.0 = ((self.0 & !((#mask) << #index)) | (((val as #storage_ty) & #mask) << #index)); + self } } }); diff --git a/src/lib.rs b/src/lib.rs index 1eb1b21..006222c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,8 +66,8 @@ fn sixty_four_bits() { } ); let mut bits = Bits(0xFF00FF00FF00FF00); - bits.set_j(0b0000000); - assert_eq!(bits.0, 0x0100FF00FF00FF00); + bits.set_j(0b0000000).set_i(0b1111111).set_a(0b1); + assert_eq!(bits.0, 0x01FCFF00FF00FF01); } macro_rules! test_width { From 486707cb8a05b1e28631eeb1d78a6461c4157009 Mon Sep 17 00:00:00 2001 From: winstonallo Date: Thu, 25 Sep 2025 18:17:33 +0200 Subject: [PATCH 2/4] Make paths stricter in tests.yml --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b5ee778..c1f232c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,8 @@ on: push: branches: ["*"] paths: - - macros/** + - macros/src/** + - macros/tests/** - src/** - tests/** - Cargo.toml From 52f82b64b0bd8770b07ec2a329b1a3d933b206d1 Mon Sep 17 00:00:00 2001 From: winstonallo Date: Thu, 25 Sep 2025 18:21:55 +0200 Subject: [PATCH 3/4] Clean up trigger configs in workflows --- .github/workflows/clippy.yml | 5 ++++- .github/workflows/rustfmt.yml | 7 +++++-- .github/workflows/tests.yml | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 920587b..cfc5350 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -1,13 +1,16 @@ name: clippy on: - push: + push: &trigger_config branches: ["*"] paths: + - macros/** - src/** - tests/** - Cargo.toml - Cargo.lock - .github/workflows/clippy.yml + pull_request: + <<: *trigger_config jobs: run-clippy: runs-on: ubuntu-latest diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index b349cde..3776fe8 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -1,13 +1,16 @@ name: rustfmt on: - push: + push: &trigger_config branches: ["*"] paths: + - macros/** - src/** - tests/** - Cargo.toml - Cargo.lock - - .github/workflows/rustfmt.yml + - .github/workflows/clippy.yml + pull_request: + <<: *trigger_config jobs: run-rustfmt: runs-on: ubuntu-latest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c1f232c..d0bf145 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,15 +1,16 @@ name: unit tests on: - push: + push: &trigger_config branches: ["*"] paths: - - macros/src/** - - macros/tests/** + - macros/** - src/** - tests/** - Cargo.toml - Cargo.lock - .github/workflows/tests.yml + pull_request: + <<: *trigger_config jobs: run-cargo-test: runs-on: ubuntu-latest From c3a9ebe4edbe8d817b761a3a8b426ba7d18de237 Mon Sep 17 00:00:00 2001 From: winstonallo Date: Thu, 25 Sep 2025 18:24:31 +0200 Subject: [PATCH 4/4] Fix clippy errors --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 006222c..d796bfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,11 @@ //! use macros::bitmap; //! //! bitmap!( -//! struct Player { -//! imposter: u1, -//! finished_tasks: u3, -//! kills: u3, -//! } +//! struct Player { +//! imposter: u1, +//! finished_tasks: u3, +//! kills: u3, +//! } //! ); //! //! let mut player = Player(0);