Skip to content

Immutable components#468

Merged
Shatur merged 5 commits intobevy-0.16-devfrom
immutable-components
Apr 22, 2025
Merged

Immutable components#468
Shatur merged 5 commits intobevy-0.16-devfrom
immutable-components

Conversation

@Shatur
Copy link
Copy Markdown
Contributor

@Shatur Shatur commented Apr 19, 2025

Immutable components were introduced in Bevy via: bevyengine/bevy#16372
These components can only be changed via re-insertion. This allows users to enforce invariants through triggers and hooks.

When porting to 0.16, I initially added a Mutability = Mutable constraint. In this PR, to support immutable components, I replaced this constraint with the MutWrite trait. It is implemented for both Mutable and Immutable markers to select the appropriate write function. For Immutable components, this function always performs insertion.

Shatur added 2 commits April 19, 2025 17:27
Immutable components were introduced in Bevy via: bevyengine/bevy#16372
These components can only be changed via re-insertion. This allows users to enforce invariants through triggers and hooks.

When porting to 0.16, I initially added a `Mutability = Mutable` constraint.
To support immutable components, I replaced this constraint with the `MutWrite` trait.
It is implemented for both `Mutable` and `Immutable` markers to select the appropriate write function.
For `Immutable` components, this function always performs insertion.
@Shatur Shatur requested a review from UkoeHB April 19, 2025 16:52
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Project coverage is 79.86%. Comparing base (cb714eb) to head (7c82e66).
Report is 4 commits behind head on bevy-0.16-dev.

Files with missing lines Patch % Lines
...ed/replication/replication_registry/command_fns.rs 80.00% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           bevy-0.16-dev     #468      +/-   ##
=================================================
- Coverage          79.87%   79.86%   -0.02%     
=================================================
  Files                 52       52              
  Lines               2768     2776       +8     
=================================================
+ Hits                2211     2217       +6     
- Misses               557      559       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}

#[test]
fn immutable() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test for re-inserting an immutable component with different value.

Shatur and others added 2 commits April 22, 2025 10:33
Co-authored-by: UkoeHB <37489173+UkoeHB@users.noreply.github.com>
@Shatur Shatur requested a review from UkoeHB April 22, 2025 15:54
@Shatur Shatur merged commit ecc8466 into bevy-0.16-dev Apr 22, 2025
8 checks passed
@Shatur Shatur deleted the immutable-components branch April 22, 2025 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants