Skip to content

Commit 5fb5c6a

Browse files
committed
Document impl_reflect_value and impl_from_reflect_value
1 parent 94490cb commit 5fb5c6a

File tree

1 file changed

+39
-0
lines changed
  • crates/bevy_reflect/bevy_reflect_derive/src

1 file changed

+39
-0
lines changed

crates/bevy_reflect/bevy_reflect_derive/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
245245
trait_reflection::reflect_trait(&args, input)
246246
}
247247

248+
/// A macro used to generate reflection trait implementations for the given type.
249+
///
250+
/// This is functionally the same as [deriving `Reflect`] using the `#[reflect_value]` container attribute.
251+
///
252+
/// The only reason for this macro's existence is so that `bevy_reflect` can easily implement the reflection traits
253+
/// on primitives and other Rust types internally.
254+
///
255+
/// # Examples
256+
///
257+
/// Types can be passed with or without registering type data:
258+
///
259+
/// ```ignore
260+
/// impl_reflect_value!(foo);
261+
/// impl_reflect_value!(bar(Debug, Default, Serialize, Deserialize));
262+
/// ```
263+
///
264+
/// Generic types can also specify their parameters and bounds:
265+
///
266+
/// ```ignore
267+
/// impl_reflect_value!(foo<T1, T2: Baz> where T1: Bar (Default, Serialize, Deserialize));
268+
/// ```
269+
///
270+
/// [deriving `Reflect`]: Reflect
248271
#[proc_macro]
249272
pub fn impl_reflect_value(input: TokenStream) -> TokenStream {
250273
let def = parse_macro_input!(input as ReflectValueDef);
@@ -326,6 +349,22 @@ pub fn impl_reflect_struct(input: TokenStream) -> TokenStream {
326349
}
327350
}
328351

352+
/// A macro used to generate a `FromReflect` trait implementation for the given type.
353+
///
354+
/// This is functionally the same as [deriving `FromReflect`] on a type that [derives `Reflect`] using
355+
/// the `#[reflect_value]` container attribute.
356+
///
357+
/// The only reason this macro exists is so that `bevy_reflect` can easily implement `FromReflect` on
358+
/// primitives and other Rust types internally.
359+
///
360+
/// # Examples
361+
///
362+
/// ```ignore
363+
/// impl_from_reflect_value!(foo<T1, T2: Baz> where T1: Bar);
364+
/// ```
365+
///
366+
/// [deriving `FromReflect`]: FromReflect
367+
/// [derives `Reflect`]: Reflect
329368
#[proc_macro]
330369
pub fn impl_from_reflect_value(input: TokenStream) -> TokenStream {
331370
let def = parse_macro_input!(input as ReflectValueDef);

0 commit comments

Comments
 (0)