Skip to content

Commit dbf14ec

Browse files
committed
Document impl_reflect_value and impl_from_reflect_value
1 parent 6dd8fa0 commit dbf14ec

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

+39
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,29 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
247247
trait_reflection::reflect_trait(&args, input)
248248
}
249249

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

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

0 commit comments

Comments
 (0)