moonshine_util/
reflect.rs

1//! Utilities related to reflection.
2
3use bevy_reflect::{FromReflect, GetTypeRegistration, Typed};
4
5/// Convenient alias for [`GetTypeRegistration`] + [`Typed`].
6///
7/// # Usage
8///
9/// When implementing generic plugins that use [`register_type`](bevy_app::App::register_type),
10/// it is often required for types to implement [`GetTypeRegistration`] and [`Typed`].
11///
12/// This is a convenient alias to avoid having to explicitly import these traits when dealing with
13/// generic code:
14///
15/// ```rust
16/// use bevy::prelude::*;
17/// use moonshine_util::prelude::*;
18///
19/// // Easy and clean! :D
20/// fn register_component_plugin<A: Registerable + Component>(app: &mut App) {
21///     app.register_type::<A>();
22/// }
23/// ```
24pub trait Registerable: GetTypeRegistration + Typed + FromReflect {}
25
26impl<T: GetTypeRegistration + Typed + FromReflect> Registerable for T {}