Skip to main content

bevy_ecs/reflect/
resource.rs

1//! Definitions for [`Resource`] reflection.
2//!
3//! # Architecture
4//!
5//! See the module doc for [`reflect::component`](`crate::reflect::component`).
6
7use crate::{reflect::ReflectComponent, resource::Resource};
8use bevy_reflect::{FromReflect, FromType, TypePath, TypeRegistration};
9
10/// A struct that marks a reflected [`Resource`] of a type.
11///
12/// This is struct does not provide any functionality.
13/// It implies the existence of a reflected [`Component`](crate::component::Component) of the same type,
14/// which is meant to be used instead.
15///
16/// ```rust,ignore
17/// #[derive(Resource, Reflect)]
18/// #[reflect(Resource)]
19/// struct ResA;
20///
21/// // is the same as:
22///
23/// #[derive(Resource, Component, Reflect)]
24/// #[reflect(Resource, Component)]
25/// struct ResA;
26/// ```
27///
28/// A [`ReflectResource`] for type `T` can be obtained via
29/// [`bevy_reflect::TypeRegistration::data`].
30#[derive(Clone)]
31pub struct ReflectResource;
32
33impl<R: Resource + FromReflect + TypePath> FromType<R> for ReflectResource {
34    fn from_type() -> Self {
35        ReflectResource
36    }
37
38    fn insert_dependencies(type_registration: &mut TypeRegistration) {
39        type_registration.register_type_data::<ReflectComponent, R>();
40    }
41}