Skip to content

Commit d2ca7dd

Browse files
committed
Automatically derive FromReflect with Reflect
1 parent 84de9e7 commit d2ca7dd

File tree

62 files changed

+355
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+355
-433
lines changed

crates/bevy_animation/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_core::Name;
1212
use bevy_ecs::prelude::*;
1313
use bevy_hierarchy::{Children, Parent};
1414
use bevy_math::{Quat, Vec3};
15-
use bevy_reflect::{FromReflect, Reflect, TypeUuid};
15+
use bevy_reflect::{Reflect, TypeUuid};
1616
use bevy_time::Time;
1717
use bevy_transform::{prelude::Transform, TransformSystem};
1818
use bevy_utils::{tracing::warn, HashMap};
@@ -26,7 +26,7 @@ pub mod prelude {
2626
}
2727

2828
/// List of keyframes for one of the attribute of a [`Transform`].
29-
#[derive(Reflect, FromReflect, Clone, Debug)]
29+
#[derive(Reflect, Clone, Debug)]
3030
pub enum Keyframes {
3131
/// Keyframes for rotation.
3232
Rotation(Vec<Quat>),
@@ -39,7 +39,7 @@ pub enum Keyframes {
3939
/// Describes how an attribute of a [`Transform`] should be animated.
4040
///
4141
/// `keyframe_timestamps` and `keyframes` should have the same length.
42-
#[derive(Reflect, FromReflect, Clone, Debug)]
42+
#[derive(Reflect, Clone, Debug)]
4343
pub struct VariableCurve {
4444
/// Timestamp for each of the keyframes.
4545
pub keyframe_timestamps: Vec<f32>,
@@ -48,14 +48,14 @@ pub struct VariableCurve {
4848
}
4949

5050
/// Path to an entity, with [`Name`]s. Each entity in a path must have a name.
51-
#[derive(Reflect, FromReflect, Clone, Debug, Hash, PartialEq, Eq, Default)]
51+
#[derive(Reflect, Clone, Debug, Hash, PartialEq, Eq, Default)]
5252
pub struct EntityPath {
5353
/// Parts of the path
5454
pub parts: Vec<Name>,
5555
}
5656

5757
/// A list of [`VariableCurve`], and the [`EntityPath`] to which they apply.
58-
#[derive(Reflect, FromReflect, Clone, TypeUuid, Debug, Default)]
58+
#[derive(Reflect, Clone, TypeUuid, Debug, Default)]
5959
#[uuid = "d81b7179-0448-4eb0-89fe-c067222725bf"]
6060
pub struct AnimationClip {
6161
curves: Vec<Vec<VariableCurve>>,

crates/bevy_asset/src/handle.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,14 @@ use crate::{
1010
Asset, Assets,
1111
};
1212
use bevy_ecs::{component::Component, reflect::ReflectComponent};
13-
use bevy_reflect::{
14-
std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectSerialize,
15-
};
13+
use bevy_reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize};
1614
use bevy_utils::Uuid;
1715
use crossbeam_channel::{Receiver, Sender};
1816
use serde::{Deserialize, Serialize};
1917

2018
/// A unique, stable asset id.
2119
#[derive(
22-
Debug,
23-
Clone,
24-
Copy,
25-
Eq,
26-
PartialEq,
27-
Hash,
28-
Ord,
29-
PartialOrd,
30-
Serialize,
31-
Deserialize,
32-
Reflect,
33-
FromReflect,
20+
Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect,
3421
)]
3522
#[reflect_value(Serialize, Deserialize, PartialEq, Hash)]
3623
pub enum HandleId {
@@ -102,7 +89,7 @@ impl HandleId {
10289
/// handle to the unloaded asset, but it will not be able to retrieve the image data, resulting in
10390
/// collisions no longer being detected for that entity.
10491
///
105-
#[derive(Component, Reflect, FromReflect)]
92+
#[derive(Component, Reflect)]
10693
#[reflect(Component, Default)]
10794
pub struct Handle<T>
10895
where

crates/bevy_asset/src/path.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use bevy_reflect::{
2-
FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect, ReflectSerialize,
3-
};
1+
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
42
use bevy_utils::{AHasher, RandomState};
53
use serde::{Deserialize, Serialize};
64
use std::{
@@ -10,8 +8,8 @@ use std::{
108
};
119

1210
/// Represents a path to an asset in the file system.
13-
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, Reflect, FromReflect)]
14-
#[reflect(Debug, PartialEq, Hash, Serialize, Deserialize, FromReflect)]
11+
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize, Reflect)]
12+
#[reflect(Debug, PartialEq, Hash, Serialize, Deserialize)]
1513
pub struct AssetPath<'a> {
1614
path: Cow<'a, Path>,
1715
label: Option<Cow<'a, str>>,

crates/bevy_asset/src/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ mod tests {
254254
use std::any::TypeId;
255255

256256
use bevy_app::{App, AppTypeRegistry};
257-
use bevy_reflect::{FromReflect, Reflect, ReflectMut, TypeUuid};
257+
use bevy_reflect::{Reflect, ReflectMut, TypeUuid};
258258

259259
use crate::{AddAsset, AssetPlugin, HandleUntyped, ReflectAsset};
260260

261-
#[derive(Reflect, FromReflect, TypeUuid)]
261+
#[derive(Reflect, TypeUuid)]
262262
#[uuid = "09191350-1238-4736-9a89-46f04bda6966"]
263263
struct AssetType {
264264
field: String,

crates/bevy_core/src/name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use bevy_ecs::{
22
component::Component, entity::Entity, query::WorldQuery, reflect::ReflectComponent,
33
};
4+
use bevy_reflect::std_traits::ReflectDefault;
45
use bevy_reflect::Reflect;
5-
use bevy_reflect::{std_traits::ReflectDefault, FromReflect};
66
use bevy_utils::AHasher;
77
use std::{
88
borrow::Cow,
@@ -17,7 +17,7 @@ use std::{
1717
/// [`Name`] should not be treated as a globally unique identifier for entities,
1818
/// as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be
1919
/// used instead as the default unique identifier.
20-
#[derive(Reflect, FromReflect, Component, Clone)]
20+
#[derive(Reflect, Component, Clone)]
2121
#[reflect(Component, Default, Debug)]
2222
pub struct Name {
2323
hash: u64, // TODO: Shouldn't be serialized

crates/bevy_core_pipeline/src/fxaa/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use bevy_app::prelude::*;
77
use bevy_asset::{load_internal_asset, HandleUntyped};
88
use bevy_derive::Deref;
99
use bevy_ecs::prelude::*;
10-
use bevy_reflect::{
11-
std_traits::ReflectDefault, FromReflect, Reflect, ReflectFromReflect, TypeUuid,
12-
};
10+
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypeUuid};
1311
use bevy_render::{
1412
extract_component::{ExtractComponent, ExtractComponentPlugin},
1513
prelude::Camera,
@@ -26,8 +24,8 @@ mod node;
2624

2725
pub use node::FxaaNode;
2826

29-
#[derive(Reflect, FromReflect, Eq, PartialEq, Hash, Clone, Copy)]
30-
#[reflect(FromReflect, PartialEq, Hash)]
27+
#[derive(Reflect, Eq, PartialEq, Hash, Clone, Copy)]
28+
#[reflect(PartialEq, Hash)]
3129
pub enum Sensitivity {
3230
Low,
3331
Medium,
@@ -48,8 +46,8 @@ impl Sensitivity {
4846
}
4947
}
5048

51-
#[derive(Reflect, FromReflect, Component, Clone, ExtractComponent)]
52-
#[reflect(Component, FromReflect, Default)]
49+
#[derive(Reflect, Component, Clone, ExtractComponent)]
50+
#[reflect(Component, Default)]
5351
#[extract_component_filter(With<Camera>)]
5452
pub struct Fxaa {
5553
/// Enable render passes for FXAA.

crates/bevy_core_pipeline/src/tonemapping/mod.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
22
use bevy_app::prelude::*;
33
use bevy_asset::{load_internal_asset, Assets, Handle, HandleUntyped};
44
use bevy_ecs::prelude::*;
5-
use bevy_reflect::{FromReflect, Reflect, TypeUuid};
5+
use bevy_reflect::{Reflect, TypeUuid};
66
use bevy_render::camera::Camera;
77
use bevy_render::extract_component::{ExtractComponent, ExtractComponentPlugin};
88
use bevy_render::extract_resource::{ExtractResource, ExtractResourcePlugin};
@@ -114,17 +114,7 @@ pub struct TonemappingPipeline {
114114

115115
/// Optionally enables a tonemapping shader that attempts to map linear input stimulus into a perceptually uniform image for a given [`Camera`] entity.
116116
#[derive(
117-
Component,
118-
Debug,
119-
Hash,
120-
Clone,
121-
Copy,
122-
Reflect,
123-
Default,
124-
ExtractComponent,
125-
PartialEq,
126-
Eq,
127-
FromReflect,
117+
Component, Debug, Hash, Clone, Copy, Reflect, Default, ExtractComponent, PartialEq, Eq,
128118
)]
129119
#[extract_component_filter(With<Camera>)]
130120
#[reflect(Component)]
@@ -301,17 +291,7 @@ pub fn queue_view_tonemapping_pipelines(
301291
}
302292
/// Enables a debanding shader that applies dithering to mitigate color banding in the final image for a given [`Camera`] entity.
303293
#[derive(
304-
Component,
305-
Debug,
306-
Hash,
307-
Clone,
308-
Copy,
309-
Reflect,
310-
Default,
311-
ExtractComponent,
312-
PartialEq,
313-
Eq,
314-
FromReflect,
294+
Component, Debug, Hash, Clone, Copy, Reflect, Default, ExtractComponent, PartialEq, Eq,
315295
)]
316296
#[extract_component_filter(With<Camera>)]
317297
#[reflect(Component)]

crates/bevy_ecs/src/reflect.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use crate::{
1010
EntityMut, EntityRef, FromWorld, World,
1111
},
1212
};
13-
use bevy_reflect::{
14-
impl_from_reflect_value, impl_reflect_value, FromType, Reflect, ReflectDeserialize,
15-
ReflectSerialize,
16-
};
13+
use bevy_reflect::{impl_reflect_value, FromType, Reflect, ReflectDeserialize, ReflectSerialize};
1714

1815
/// A struct used to operate on reflected [`Component`] of a type.
1916
///
@@ -408,7 +405,6 @@ impl<C: Resource + Reflect + FromWorld> FromType<C> for ReflectResource {
408405
}
409406

410407
impl_reflect_value!((in bevy_ecs) Entity(Hash, PartialEq, Serialize, Deserialize));
411-
impl_from_reflect_value!(Entity);
412408

413409
/// For a specific type of component, this maps any fields with values of type [`Entity`] to a new world.
414410
/// Since a given `Entity` ID is only valid for the world it came frome, when performing deserialization

crates/bevy_gizmos/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ use bevy_ecs::{
3333
Commands, Query, Res, ResMut, Resource, SystemParamItem,
3434
},
3535
};
36-
use bevy_reflect::{
37-
std_traits::ReflectDefault, FromReflect, Reflect, ReflectFromReflect, TypePath, TypeUuid,
38-
};
36+
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath, TypeUuid};
3937
use bevy_render::{
4038
color::Color,
4139
extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin},
@@ -191,8 +189,8 @@ pub struct AabbGizmoConfig {
191189
}
192190

193191
/// Add this [`Component`] to an entity to draw its [`Aabb`] component.
194-
#[derive(Component, Reflect, FromReflect, Default, Debug)]
195-
#[reflect(Component, FromReflect, Default)]
192+
#[derive(Component, Reflect, Default, Debug)]
193+
#[reflect(Component, Default)]
196194
pub struct AabbGizmo {
197195
/// The color of the box.
198196
///

0 commit comments

Comments
 (0)