Minor code readability improvement in enum_utility.access_field (#19961)

Small cleanup copied from https://github.com/bevyengine/bevy/pull/16250
This commit is contained in:
theotherphil 2025-07-05 15:40:23 +01:00 committed by GitHub
parent bdb39cf723
commit a869383cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,20 +48,15 @@ pub(crate) trait VariantBuilder: Sized {
/// * `this`: The identifier of the enum
/// * `field`: The field to access
fn access_field(&self, this: &Ident, field: VariantField) -> TokenStream {
match &field.field.data.ident {
Some(field_ident) => {
let name = field_ident.to_string();
quote!(#this.field(#name))
}
None => {
if let Some(field_index) = field.field.reflection_index {
quote!(#this.field_at(#field_index))
} else {
quote!(::core::compile_error!(
"internal bevy_reflect error: field should be active"
))
}
}
if let Some(field_ident) = &field.field.data.ident {
let name = field_ident.to_string();
quote!(#this.field(#name))
} else if let Some(field_index) = field.field.reflection_index {
quote!(#this.field_at(#field_index))
} else {
quote!(::core::compile_error!(
"internal bevy_reflect error: field should be active"
))
}
}