Skip to content

bsn: support field name shorthand#24526

Open
cart wants to merge 1 commit into
bevyengine:mainfrom
cart:bsn-name-shorthand
Open

bsn: support field name shorthand#24526
cart wants to merge 1 commit into
bevyengine:mainfrom
cart:bsn-name-shorthand

Conversation

@cart
Copy link
Copy Markdown
Member

@cart cart commented Jun 4, 2026

Objective

bsn! should support Rust's "name shorthand syntax":

let value = 10;
Foo { value }

Solution

Add support, both for normal types and "props":

let value = 10;
bsn! {
  Foo { value }
}

let value = 10;
bsn! {
  @Foo { @value }  
}

This also changes generated internal bsn! variables to use __X formatting everywhere to avoid conflicts with user-defined variables (we were already using this strategy in some places ... this just uses it everywhere).

Testing

  • added a test

@cart cart added this to the 0.19 milestone Jun 4, 2026
@cart cart added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Composing and serializing ECS objects labels Jun 4, 2026
@kfc35 kfc35 added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jun 6, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

looks good to me, have to resolve conflicts

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 6, 2026
Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

The code generation doesn't match the equivalent explicit version, suppose value is a u32 field:

let value = 10u8;
bsn! {
  Foo { value: value }
}

works because it adds an into() but not with:

let value = 10u8;
bsn! {
  Foo { value }
}

which results in a type mismatch error.

@laundmo
Copy link
Copy Markdown
Member

laundmo commented Jun 6, 2026

This should be added to docs (at least the syntax table) once #24464 is merged

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants