Skip to content

Commit 7fc6db3

Browse files
Add FromReflect where Reflect is used (#8776)
# Objective Discovered that PointLight did not implement FromReflect. Adding FromReflect where Reflect is used. I overreached and applied this rule everywhere there was a Reflect without a FromReflect, except from where the compiler wouldn't allow me. Based from question: #8774 ## Solution - Adding FromReflect where Reflect was already derived ## Notes First PR I do in this ecosystem, so not sure if this is the usual approach, that is, to touch many files at once. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 23863d5 commit 7fc6db3

File tree

39 files changed

+225
-185
lines changed

39 files changed

+225
-185
lines changed

crates/bevy_asset/src/handle.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{
1111
};
1212
use bevy_ecs::{component::Component, reflect::ReflectComponent};
1313
use bevy_reflect::{
14-
std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectSerialize,
14+
std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect,
15+
ReflectSerialize,
1516
};
1617
use bevy_utils::Uuid;
1718
use crossbeam_channel::{Receiver, Sender};
@@ -103,7 +104,7 @@ impl HandleId {
103104
/// collisions no longer being detected for that entity.
104105
///
105106
#[derive(Component, Reflect, FromReflect)]
106-
#[reflect(Component, Default)]
107+
#[reflect(Component, Default, FromReflect)]
107108
pub struct Handle<T>
108109
where
109110
T: Asset,

crates/bevy_asset/src/path.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,38 @@ impl<'a> AssetPath<'a> {
6969

7070
/// An unique identifier to an asset path.
7171
#[derive(
72-
Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect,
72+
Debug,
73+
Clone,
74+
Copy,
75+
Eq,
76+
PartialEq,
77+
Hash,
78+
Ord,
79+
PartialOrd,
80+
Serialize,
81+
Deserialize,
82+
Reflect,
83+
FromReflect,
7384
)]
74-
#[reflect_value(PartialEq, Hash, Serialize, Deserialize)]
85+
#[reflect_value(PartialEq, Hash, Serialize, Deserialize, FromReflect)]
7586
pub struct AssetPathId(SourcePathId, LabelId);
7687

7788
/// An unique identifier to the source path of an asset.
7889
#[derive(
79-
Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize, Reflect,
90+
Debug,
91+
Clone,
92+
Copy,
93+
Eq,
94+
PartialEq,
95+
Hash,
96+
Ord,
97+
PartialOrd,
98+
Serialize,
99+
Deserialize,
100+
Reflect,
101+
FromReflect,
80102
)]
81-
#[reflect_value(PartialEq, Hash, Serialize, Deserialize)]
103+
#[reflect_value(PartialEq, Hash, Serialize, Deserialize, FromReflect)]
82104
pub struct SourcePathId(u64);
83105

84106
/// An unique identifier to a sub-asset label.

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::Reflect;
54
use bevy_reflect::{std_traits::ReflectDefault, FromReflect};
5+
use bevy_reflect::{Reflect, ReflectFromReflect};
66
use bevy_utils::AHasher;
77
use std::{
88
borrow::Cow,
@@ -18,7 +18,7 @@ use std::{
1818
/// as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be
1919
/// used instead as the default unique identifier.
2020
#[derive(Reflect, FromReflect, Component, Clone)]
21-
#[reflect(Component, Default, Debug)]
21+
#[reflect(Component, Default, Debug, FromReflect)]
2222
pub struct Name {
2323
hash: u64, // TODO: Shouldn't be serialized
2424
name: Cow<'static, str>,

crates/bevy_core_pipeline/src/bloom/settings.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::downsampling_pipeline::BloomUniforms;
22
use bevy_ecs::{prelude::Component, query::QueryItem, reflect::ReflectComponent};
33
use bevy_math::{UVec4, Vec4};
4-
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
4+
use bevy_reflect::{std_traits::ReflectDefault, FromReflect, Reflect, ReflectFromReflect};
55
use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
66

77
/// Applies a bloom effect to an HDR-enabled 2d or 3d camera.
@@ -160,7 +160,8 @@ impl Default for BloomSettings {
160160
/// * Changing these settings creates a physically inaccurate image
161161
/// * Changing these settings makes it easy to make the final result look worse
162162
/// * Non-default prefilter settings should be used in conjuction with [`BloomCompositeMode::Additive`]
163-
#[derive(Default, Clone, Reflect)]
163+
#[derive(Default, Clone, Reflect, FromReflect)]
164+
#[reflect(FromReflect)]
164165
pub struct BloomPrefilterSettings {
165166
/// Baseline of the quadratic threshold curve (default: 0.0).
166167
///

crates/bevy_core_pipeline/src/clear_color.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use bevy_derive::{Deref, DerefMut};
22
use bevy_ecs::prelude::*;
3-
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
3+
use bevy_reflect::{
4+
FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect, ReflectSerialize,
5+
};
46
use bevy_render::{color::Color, extract_resource::ExtractResource};
57
use serde::{Deserialize, Serialize};
68

7-
#[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)]
8-
#[reflect(Serialize, Deserialize)]
9+
#[derive(Reflect, FromReflect, Serialize, Deserialize, Clone, Debug, Default)]
10+
#[reflect(Serialize, Deserialize, FromReflect)]
911
pub enum ClearColorConfig {
1012
#[default]
1113
Default,
@@ -17,8 +19,8 @@ pub enum ClearColorConfig {
1719
///
1820
/// This color appears as the "background" color for simple apps,
1921
/// when there are portions of the screen with nothing rendered.
20-
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)]
21-
#[reflect(Resource)]
22+
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect, FromReflect)]
23+
#[reflect(Resource, FromReflect)]
2224
pub struct ClearColor(pub Color);
2325

2426
impl Default for ClearColor {

crates/bevy_core_pipeline/src/core_2d/camera_2d.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
tonemapping::{DebandDither, Tonemapping},
44
};
55
use bevy_ecs::prelude::*;
6-
use bevy_reflect::Reflect;
6+
use bevy_reflect::{FromReflect, Reflect, ReflectFromReflect};
77
use bevy_render::{
88
camera::{Camera, CameraProjection, CameraRenderGraph, OrthographicProjection},
99
extract_component::ExtractComponent,
@@ -12,9 +12,9 @@ use bevy_render::{
1212
};
1313
use bevy_transform::prelude::{GlobalTransform, Transform};
1414

15-
#[derive(Component, Default, Reflect, Clone, ExtractComponent)]
15+
#[derive(Component, Default, Reflect, FromReflect, Clone, ExtractComponent)]
1616
#[extract_component_filter(With<Camera>)]
17-
#[reflect(Component)]
17+
#[reflect(Component, FromReflect)]
1818
pub struct Camera2d {
1919
pub clear_color: ClearColorConfig,
2020
}

crates/bevy_core_pipeline/src/core_3d/camera_3d.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use crate::{
33
tonemapping::{DebandDither, Tonemapping},
44
};
55
use bevy_ecs::prelude::*;
6-
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
6+
use bevy_reflect::{
7+
FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect, ReflectSerialize,
8+
};
79
use bevy_render::{
810
camera::{Camera, CameraRenderGraph, Projection},
911
extract_component::ExtractComponent,
@@ -15,9 +17,9 @@ use bevy_transform::prelude::{GlobalTransform, Transform};
1517
use serde::{Deserialize, Serialize};
1618

1719
/// Configuration for the "main 3d render graph".
18-
#[derive(Component, Reflect, Clone, ExtractComponent)]
20+
#[derive(Component, Reflect, FromReflect, Clone, ExtractComponent)]
1921
#[extract_component_filter(With<Camera>)]
20-
#[reflect(Component)]
22+
#[reflect(Component, FromReflect)]
2123
pub struct Camera3d {
2224
/// The clear color operation to perform for the main 3d pass.
2325
pub clear_color: ClearColorConfig,
@@ -37,7 +39,8 @@ impl Default for Camera3d {
3739
}
3840
}
3941

40-
#[derive(Clone, Copy, Reflect)]
42+
#[derive(Clone, Copy, Reflect, FromReflect)]
43+
#[reflect(FromReflect)]
4144
pub struct Camera3dDepthTextureUsage(u32);
4245

4346
impl From<TextureUsages> for Camera3dDepthTextureUsage {
@@ -52,8 +55,8 @@ impl From<Camera3dDepthTextureUsage> for TextureUsages {
5255
}
5356

5457
/// The depth clear operation to perform for the main 3d pass.
55-
#[derive(Reflect, Serialize, Deserialize, Clone, Debug)]
56-
#[reflect(Serialize, Deserialize)]
58+
#[derive(Reflect, FromReflect, Serialize, Deserialize, Clone, Debug)]
59+
#[reflect(Serialize, Deserialize, FromReflect)]
5760
pub enum Camera3dDepthLoadOp {
5861
/// Clear with a specified value.
5962
/// Note that 0.0 is the far plane due to bevy's use of reverse-z projections.

crates/bevy_core_pipeline/src/prepass/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub mod node;
3030
use std::cmp::Reverse;
3131

3232
use bevy_ecs::prelude::*;
33-
use bevy_reflect::Reflect;
33+
use bevy_reflect::{FromReflect, Reflect, ReflectFromReflect};
3434
use bevy_render::{
3535
render_phase::{CachedRenderPipelinePhaseItem, DrawFunctionId, PhaseItem},
3636
render_resource::{CachedRenderPipelineId, Extent3d, TextureFormat},
@@ -43,16 +43,19 @@ pub const NORMAL_PREPASS_FORMAT: TextureFormat = TextureFormat::Rgb10a2Unorm;
4343
pub const MOTION_VECTOR_PREPASS_FORMAT: TextureFormat = TextureFormat::Rg16Float;
4444

4545
/// If added to a [`crate::prelude::Camera3d`] then depth values will be copied to a separate texture available to the main pass.
46-
#[derive(Component, Default, Reflect)]
46+
#[derive(Component, Default, Reflect, FromReflect)]
47+
#[reflect(FromReflect)]
4748
pub struct DepthPrepass;
4849

4950
/// If added to a [`crate::prelude::Camera3d`] then vertex world normals will be copied to a separate texture available to the main pass.
5051
/// Normals will have normal map textures already applied.
51-
#[derive(Component, Default, Reflect)]
52+
#[derive(Component, Default, Reflect, FromReflect)]
53+
#[reflect(FromReflect)]
5254
pub struct NormalPrepass;
5355

5456
/// If added to a [`crate::prelude::Camera3d`] then screen space motion vectors will be copied to a separate texture available to the main pass.
55-
#[derive(Component, Default, Reflect)]
57+
#[derive(Component, Default, Reflect, FromReflect)]
58+
#[reflect(FromReflect)]
5659
pub struct MotionVectorPrepass;
5760

5861
/// Textures that are written to by the prepass.

crates/bevy_core_pipeline/src/tonemapping/mod.rs

Lines changed: 3 additions & 3 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::{FromReflect, Reflect, ReflectFromReflect, TypeUuid};
66
use bevy_render::camera::Camera;
77
use bevy_render::extract_component::{ExtractComponent, ExtractComponentPlugin};
88
use bevy_render::extract_resource::{ExtractResource, ExtractResourcePlugin};
@@ -127,7 +127,7 @@ pub struct TonemappingPipeline {
127127
FromReflect,
128128
)]
129129
#[extract_component_filter(With<Camera>)]
130-
#[reflect(Component)]
130+
#[reflect(Component, FromReflect)]
131131
pub enum Tonemapping {
132132
/// Bypass tonemapping.
133133
None,
@@ -314,7 +314,7 @@ pub fn queue_view_tonemapping_pipelines(
314314
FromReflect,
315315
)]
316316
#[extract_component_filter(With<Camera>)]
317-
#[reflect(Component)]
317+
#[reflect(Component, FromReflect)]
318318
pub enum DebandDither {
319319
#[default]
320320
Disabled,

crates/bevy_gltf/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_app::prelude::*;
1212
use bevy_asset::{AddAsset, Handle};
1313
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
1414
use bevy_pbr::StandardMaterial;
15-
use bevy_reflect::{Reflect, TypePath, TypeUuid};
15+
use bevy_reflect::{FromReflect, Reflect, ReflectFromReflect, TypePath, TypeUuid};
1616
use bevy_render::{
1717
mesh::{Mesh, MeshVertexAttribute},
1818
renderer::RenderDevice,
@@ -106,8 +106,8 @@ pub struct GltfPrimitive {
106106
pub material_extras: Option<GltfExtras>,
107107
}
108108

109-
#[derive(Clone, Debug, Reflect, Default, Component)]
110-
#[reflect(Component)]
109+
#[derive(Clone, Debug, Reflect, FromReflect, Default, Component)]
110+
#[reflect(Component, FromReflect)]
111111
pub struct GltfExtras {
112112
pub value: String,
113113
}

crates/bevy_hierarchy/src/components/children.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy_ecs::{
55
reflect::{ReflectComponent, ReflectMapEntities},
66
world::World,
77
};
8-
use bevy_reflect::Reflect;
8+
use bevy_reflect::{FromReflect, Reflect, ReflectFromReflect};
99
use core::slice;
1010
use smallvec::SmallVec;
1111
use std::ops::Deref;
@@ -16,8 +16,8 @@ use std::ops::Deref;
1616
///
1717
/// [`HierarchyQueryExt`]: crate::query_extension::HierarchyQueryExt
1818
/// [`Query`]: bevy_ecs::system::Query
19-
#[derive(Component, Debug, Reflect)]
20-
#[reflect(Component, MapEntities)]
19+
#[derive(Component, Debug, Reflect, FromReflect)]
20+
#[reflect(Component, MapEntities, FromReflect)]
2121
pub struct Children(pub(crate) SmallVec<[Entity; 8]>);
2222

2323
impl MapEntities for Children {

crates/bevy_hierarchy/src/components/parent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy_ecs::{
44
reflect::{ReflectComponent, ReflectMapEntities},
55
world::{FromWorld, World},
66
};
7-
use bevy_reflect::Reflect;
7+
use bevy_reflect::{FromReflect, Reflect, ReflectFromReflect};
88
use std::ops::Deref;
99

1010
/// Holds a reference to the parent entity of this entity.
@@ -14,8 +14,8 @@ use std::ops::Deref;
1414
///
1515
/// [`HierarchyQueryExt`]: crate::query_extension::HierarchyQueryExt
1616
/// [`Query`]: bevy_ecs::system::Query
17-
#[derive(Component, Debug, Eq, PartialEq, Reflect)]
18-
#[reflect(Component, MapEntities, PartialEq)]
17+
#[derive(Component, Debug, Eq, PartialEq, Reflect, FromReflect)]
18+
#[reflect(Component, MapEntities, PartialEq, FromReflect)]
1919
pub struct Parent(pub(crate) Entity);
2020

2121
impl Parent {

0 commit comments

Comments
 (0)