Skip to content

Commit 39f9b00

Browse files
committed
Undo vis removal for generated wrapper type
We need to provide a way for users to reference their wrapper type for use in #[reflect(remote = ...)] attributes
1 parent b330b49 commit 39f9b00

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

crates/bevy_reflect/derive/src/remote.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub(crate) fn reflect_remote(args: TokenStream, input: TokenStream) -> TokenStre
106106
/// ```
107107
fn generate_remote_wrapper(input: &DeriveInput, remote_ty: &TypePath) -> proc_macro2::TokenStream {
108108
let ident = &input.ident;
109+
let vis = &input.vis;
109110
let ty_generics = &input.generics;
110111
let where_clause = &input.generics.where_clause;
111112
let attrs = input
@@ -117,7 +118,7 @@ fn generate_remote_wrapper(input: &DeriveInput, remote_ty: &TypePath) -> proc_ma
117118
#(#attrs)*
118119
#[repr(transparent)]
119120
#[doc(hidden)]
120-
struct #ident #ty_generics (pub #remote_ty) #where_clause;
121+
#vis struct #ident #ty_generics (pub #remote_ty) #where_clause;
121122
}
122123
}
123124

crates/bevy_reflect/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,34 @@ bevy_reflect::tests::Test {
24902490
assert_eq!("Goodbye", data.0.value);
24912491
}
24922492

2493+
#[test]
2494+
fn should_reflect_remote_type_from_module() {
2495+
mod wrapper {
2496+
use super::*;
2497+
2498+
// We have to place this module internally to this one to get around the following error:
2499+
// ```
2500+
// error[E0433]: failed to resolve: use of undeclared crate or module `external_crate`
2501+
// ```
2502+
pub mod external_crate {
2503+
pub struct TheirType {
2504+
pub value: String,
2505+
}
2506+
}
2507+
2508+
#[reflect_remote(external_crate::TheirType)]
2509+
pub struct MyType {
2510+
pub value: String,
2511+
}
2512+
}
2513+
2514+
#[derive(Reflect)]
2515+
struct ContainerStruct {
2516+
#[reflect(remote = wrapper::MyType)]
2517+
their_type: wrapper::external_crate::TheirType,
2518+
}
2519+
}
2520+
24932521
#[test]
24942522
fn should_reflect_remote_enum() {
24952523
mod external_crate {

0 commit comments

Comments
 (0)