Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_ecs/src/reflect/resource.rs
9408 views
1
//! Definitions for [`Resource`] reflection.
2
//!
3
//! # Architecture
4
//!
5
//! See the module doc for [`reflect::component`](`crate::reflect::component`).
6
7
use crate::{reflect::ReflectComponent, resource::Resource};
8
use 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)]
31
pub struct ReflectResource;
32
33
impl<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
}
42
43