Skip to content

Commit

Permalink
Updated visibility of reflected trait (bevyengine#4034)
Browse files Browse the repository at this point in the history
# Objective

The `#[reflect_trait]` macro did not maintain the visibility of its trait. It also did not make its accessor methods public, which made them inaccessible outside the current module.

## Solution

Made the `Reflect***` struct match the visibility of its trait and made both the `get` and `get_mut` methods always public.
  • Loading branch information
MrGVSV committed Feb 25, 2022
1 parent c1a4a2f commit 1fa54c2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/reflect_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ pub fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStream {
let trait_info = parse_macro_input!(input as TraitInfo);
let item_trait = &trait_info.item_trait;
let trait_ident = &item_trait.ident;
let trait_vis = &item_trait.vis;
let reflect_trait_ident =
Ident::new(&format!("Reflect{}", item_trait.ident), Span::call_site());
let bevy_reflect_path = BevyManifest::default().get_path("bevy_reflect");
TokenStream::from(quote! {
#item_trait

#[derive(Clone)]
pub struct #reflect_trait_ident {
#trait_vis struct #reflect_trait_ident {
get_func: fn(&dyn #bevy_reflect_path::Reflect) -> Option<&dyn #trait_ident>,
get_mut_func: fn(&mut dyn #bevy_reflect_path::Reflect) -> Option<&mut dyn #trait_ident>,
}

impl #reflect_trait_ident {
fn get<'a>(&self, reflect_value: &'a dyn #bevy_reflect_path::Reflect) -> Option<&'a dyn #trait_ident> {
pub fn get<'a>(&self, reflect_value: &'a dyn #bevy_reflect_path::Reflect) -> Option<&'a dyn #trait_ident> {
(self.get_func)(reflect_value)
}

fn get_mut<'a>(&self, reflect_value: &'a mut dyn #bevy_reflect_path::Reflect) -> Option<&'a mut dyn #trait_ident> {
pub fn get_mut<'a>(&self, reflect_value: &'a mut dyn #bevy_reflect_path::Reflect) -> Option<&'a mut dyn #trait_ident> {
(self.get_mut_func)(reflect_value)
}
}
Expand Down

0 comments on commit 1fa54c2

Please sign in to comment.