Skip to content

Derive clone #18811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Derive clone #18811

wants to merge 11 commits into from

Conversation

Bleachfuel
Copy link
Contributor

Allow Derive(Component) to specify a clone_behavior

#[derive(Component)]
#[component(clone_behavior = Ignore)]
MyComponent;

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

We should probably also add tests for all possible variants of ComponentCloneBehavior to ensure everything parses and works as intended (or at least just the parsing part).

@Bleachfuel Bleachfuel requested a review from MrGVSV April 11, 2025 22:24
Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

Just one nitpick, otherwise looks good to me!

if attrs.relationship_target.is_some() && attrs.clone_behavior.is_some() {
return Err(syn::Error::new(
attrs.clone_behavior.span(),
format!("A Relationship Target already has it's own clone behavior, please remove `clone_behavior = {}`", attrs.clone_behavior.as_ref().unwrap().to_token_stream()),
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't think you need to provide the token value. Any clone_behavior would result in this error. Plus I believe printing the token streams can sometimes look different than the input (at least in the case of a Custom behavior).

Suggested change
format!("A Relationship Target already has it's own clone behavior, please remove `clone_behavior = {}`", attrs.clone_behavior.as_ref().unwrap().to_token_stream()),
"A Relationship Target already has its own clone behavior, please remove `clone_behavior`",

@MrGVSV MrGVSV added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward D-Macros Code that generates Rust code labels Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Macros Code that generates Rust code D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants