Allow a closure to be used as a required component default#15269
Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom Oct 4, 2024
Merged
Allow a closure to be used as a required component default#15269alice-i-cecile merged 2 commits intobevyengine:mainfrom
alice-i-cecile merged 2 commits intobevyengine:mainfrom
Conversation
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
I quite like this, but this needs user facing docs demonstrating that this is possible.
Member
|
@fluffiac do you have time to add docs, or would you like a hand finishing this off? |
Contributor
Author
|
@alice-i-cecile thank you for the reminder. kind of forgot 😅 |
alice-i-cecile
approved these changes
Oct 4, 2024
cart
approved these changes
Oct 4, 2024
Member
|
Fantastic; thanks for getting back to this! |
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Oct 4, 2024
…e#15269) # Objective Allow required component default values to be provided in-line. ```rust #[derive(Component)] #[require( FocusPolicy(block_focus_policy) )] struct SomeComponent; fn block_focus_policy() -> FocusPolicy { FocusPolicy::Block } ``` May now be expressed as: ```rust #[derive(Component)] #[require( FocusPolicy(|| FocusPolicy::Block) )] struct SomeComponent; ``` ## Solution Modified the #[require] proc macro to accept a closure. ## Testing Tested using my branch as a dependency, and switching between the inline closure syntax and function syntax for a bunch of different components.
robtfm
pushed a commit
to robtfm/bevy
that referenced
this pull request
Oct 4, 2024
…e#15269) # Objective Allow required component default values to be provided in-line. ```rust #[derive(Component)] #[require( FocusPolicy(block_focus_policy) )] struct SomeComponent; fn block_focus_policy() -> FocusPolicy { FocusPolicy::Block } ``` May now be expressed as: ```rust #[derive(Component)] #[require( FocusPolicy(|| FocusPolicy::Block) )] struct SomeComponent; ``` ## Solution Modified the #[require] proc macro to accept a closure. ## Testing Tested using my branch as a dependency, and switching between the inline closure syntax and function syntax for a bunch of different components.
Member
|
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1714 if you'd like to help out. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Allow required component default values to be provided in-line.
May now be expressed as:
Solution
Modified the #[require] proc macro to accept a closure.
Testing
Tested using my branch as a dependency, and switching between the inline closure syntax and function syntax for a bunch of different components.