Skip to content
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

bevy_reflect: Default attribute paths #9323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Jul 31, 2023

Objective

Followup to #9322 but with a breaking change.

With syn2, it's a whole lot easier to customize attributes. One small improvement we could make would be to change the default attribute to take a type path directly instead of a stringified path.

Solution

Updated the parsing logic to take an ExprPath directly.


Changelog

  • Default functions passed to #[reflect(default)] no longer need to be string literals (i.e. they can specify the path directly like #[reflect(default = path::to::func)])

Migration Guide

The optional function passed to #[reflect(default)] is no longer a stringified path. It can now be a standard type path:

mod defaults {
  fn foo() -> i32 {
    123
  }
}

// BEFORE
#[derive(Reflect)]
struct Foo {
  #[reflect(default = "defaults::foo")]
  value: i32
}

// AFTER
#[derive(Reflect)]
struct Foo {
  #[reflect(default = defaults::foo)]
  value: i32
}

@MrGVSV MrGVSV added S-Blocked This cannot move forward until something else changes C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Jul 31, 2023
@MrGVSV MrGVSV force-pushed the reflect-default-attribute-parsing branch from 6a62619 to 9e04df0 Compare August 30, 2023 00:37
@MrGVSV MrGVSV removed the S-Blocked This cannot move forward until something else changes label Aug 30, 2023
@MrGVSV MrGVSV marked this pull request as ready for review August 30, 2023 00:38
Copy link
Contributor

@killercup killercup left a comment

Choose a reason for hiding this comment

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

This should also allow autocomplete to work in these cases, right?

@MrGVSV
Copy link
Member Author

MrGVSV commented Aug 30, 2023

This should also allow autocomplete to work in these cases, right?

Ideally yes, but I can't speak for all editors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants