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 b5ee778..d0bf145 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,6 @@ name: unit tests on: - push: + push: &trigger_config branches: ["*"] paths: - macros/** @@ -9,6 +9,8 @@ on: - Cargo.toml - Cargo.lock - .github/workflows/tests.yml + pull_request: + <<: *trigger_config jobs: run-cargo-test: runs-on: ubuntu-latest 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..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); @@ -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 {