@@ -100,7 +100,7 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
100100/// Generates a wrapper type that can be used to "derive `Reflect`" for remote types.
101101///
102102/// This works by wrapping the remote type in a generated wrapper that has the `#[repr(transparent)]` attribute.
103- /// This allows the two types to be safely transmuted back-and-forth.
103+ /// This allows the two types to be safely [ transmuted] back-and-forth.
104104///
105105/// # Defining the Wrapper
106106///
@@ -156,6 +156,26 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
156156/// pub struct Wrapper<T: Default + Clone>(RemoteType<T>);
157157/// ```
158158///
159+ /// # Usage as a Field
160+ ///
161+ /// You can tell `Reflect` to use a remote type's wrapper internally on fields of a struct or enum.
162+ /// This allows the real type to be used as usual while `Reflect` handles everything internally.
163+ /// To do this, add the `#[reflect(remote = "...")]` attribute to your field:
164+ ///
165+ /// ```ignore
166+ /// #[derive(Reflect)]
167+ /// struct SomeStruct {
168+ /// #[reflect(remote = "RemoteTypeWrapper")]
169+ /// data: RemoteType
170+ /// }
171+ /// ```
172+ ///
173+ /// ## Safety
174+ ///
175+ /// When using the `#[reflect(remote = "...")]` field attribute, be sure you are defining the correct wrapper type.
176+ /// Internally, this field will be unsafely [transmuted], and is only sound if using a wrapper generated for the remote type.
177+ /// This also means keeping your wrapper definitions up-to-date with the remote types.
178+ ///
159179/// # `FromReflect`
160180///
161181/// Because of the way this code modifies the item it's defined on, it is not possible to implement `FromReflect`
@@ -172,6 +192,7 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
172192/// This is the _only_ trait this works with. You cannot derive any other traits using this method.
173193/// For those, use regular derive macros below this one.
174194///
195+ /// [transmuted]: std::mem::transmute
175196#[ proc_macro_attribute]
176197pub fn reflect_remote ( args : TokenStream , input : TokenStream ) -> TokenStream {
177198 remote:: reflect_remote ( args, input)
0 commit comments