-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective #476 changed collision layers to reserve the first bit for a default layer. However, for enums implementing `PhysicsLayer`, the default layer is rather implicit and potentially footgunny. The default layer should ideally be more explicit. ## Solution Change `PhysicsLayer` to require `Default` to be implemented. The proc macro orders the variants such that the layer set as the default is always the first bit. Note that `Default` *must* currently be derived instead of implemented manually, as the macro can only access the default variant if the `#[default]` attribute exists. An error is emitted if `#[default]` does not exist. If someone knows a way to make it work with the manual impl, let me know or consider opening a PR! I also added documentation for the `PhysicsLayer` macro, and improved error handling. --- ## Migration Guide Enums that derive `PhysicsLayer` must now also derive `Default` and specify a default layer using the `#[default]` attribute. Before: ```rust #[derive(PhysicsLayer)] enum GameLayer { Player, Enemy, Ground, } ``` After: ```rust #[derive(PhysicsLayer, Default)] enum GameLayer { #[default] Default, // The name doesn't matter, but Default is used here for clarity Player, Enemy, Ground, } ``` The default layer always has the bit value `0b0001` regardless of its order relative to the other variants. --------- Co-authored-by: Jan Hohenheim <[email protected]>
- Loading branch information
1 parent
e443720
commit 89b733e
Showing
4 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ bench = false | |
|
||
[dependencies] | ||
proc-macro2 = "1.0.78" | ||
proc-macro-error = "1.0" | ||
quote = "1.0" | ||
syn = "2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters