Skip to content

Commit 2953db7

Browse files
authored
impl Eq/PartialEq for MeshMaterial{2|3}d (#17990)
# Objective `Eq`/`PartialEq` are currently implemented for `MeshMaterial{2|3}d` only through the derive macro. Since we don't have perfect derive yet, the impls are only present for `M: Eq` and `M: PartialEq`. On the other hand, I want to be able to compare material components for my toy reactivity project. ## Solution Switch to manual `Eq`/`PartialEq` impl. ## Testing Boy I hope this didn't break anything!
1 parent 8122b35 commit 2953db7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

crates/bevy_pbr/src/mesh_material.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use derive_more::derive::From;
3636
/// ));
3737
/// }
3838
/// ```
39-
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
39+
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, From)]
4040
#[reflect(Component, Default)]
4141
pub struct MeshMaterial3d<M: Material>(pub Handle<M>);
4242

@@ -46,6 +46,14 @@ impl<M: Material> Default for MeshMaterial3d<M> {
4646
}
4747
}
4848

49+
impl<M: Material> PartialEq for MeshMaterial3d<M> {
50+
fn eq(&self, other: &Self) -> bool {
51+
self.0 == other.0
52+
}
53+
}
54+
55+
impl<M: Material> Eq for MeshMaterial3d<M> {}
56+
4957
impl<M: Material> From<MeshMaterial3d<M>> for AssetId<M> {
5058
fn from(material: MeshMaterial3d<M>) -> Self {
5159
material.id()

crates/bevy_sprite/src/mesh2d/material.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub trait Material2d: AsBindGroup + Asset + Clone + Sized {
186186
/// ```
187187
///
188188
/// [`MeshMaterial2d`]: crate::MeshMaterial2d
189-
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
189+
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, From)]
190190
#[reflect(Component, Default)]
191191
pub struct MeshMaterial2d<M: Material2d>(pub Handle<M>);
192192

@@ -196,6 +196,14 @@ impl<M: Material2d> Default for MeshMaterial2d<M> {
196196
}
197197
}
198198

199+
impl<M: Material2d> PartialEq for MeshMaterial2d<M> {
200+
fn eq(&self, other: &Self) -> bool {
201+
self.0 == other.0
202+
}
203+
}
204+
205+
impl<M: Material2d> Eq for MeshMaterial2d<M> {}
206+
199207
impl<M: Material2d> From<MeshMaterial2d<M>> for AssetId<M> {
200208
fn from(material: MeshMaterial2d<M>) -> Self {
201209
material.id()

0 commit comments

Comments
 (0)