Skip to content

Commit b4392be

Browse files
committed
Deref and don't allow modifying the component id
1 parent f04efac commit b4392be

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

crates/bevy_ecs/src/component.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ impl ComponentTicks {
676676

677677
/// Initialize and fetch a component id for a generic type.
678678
pub struct ComponentIdFor<T: Component> {
679-
pub component_id: ComponentId,
679+
component_id: ComponentId,
680680
phantom: PhantomData<T>,
681681
}
682682

@@ -689,18 +689,15 @@ impl<T: Component> FromWorld for ComponentIdFor<T> {
689689
}
690690
}
691691

692-
impl<T: Component> Copy for ComponentIdFor<T> {}
693-
impl<T: Component> Clone for ComponentIdFor<T> {
694-
fn clone(&self) -> Self {
695-
Self {
696-
component_id: self.component_id,
697-
phantom: PhantomData,
698-
}
692+
impl<T: Component> std::ops::Deref for ComponentIdFor<T> {
693+
type Target = ComponentId;
694+
fn deref(&self) -> &Self::Target {
695+
&self.component_id
699696
}
700697
}
701698

702699
impl<T: Component> From<ComponentIdFor<T>> for ComponentId {
703700
fn from(to_component_id: ComponentIdFor<T>) -> ComponentId {
704-
to_component_id.component_id
701+
*to_component_id
705702
}
706703
}

crates/bevy_ecs/src/removal_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub struct RemovedComponents<'w, 's, T: Component> {
114114

115115
impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> {
116116
pub fn iter(&mut self) -> Box<dyn Iterator<Item = Entity> + '_> {
117-
if let Some(events) = self.event_sets.get(*self.component_id) {
117+
if let Some(events) = self.event_sets.get(**self.component_id) {
118118
// TODO: Make this an actually name-able type so we don't need to box
119119
Box::new(self.reader.iter(events).cloned())
120120
} else {

0 commit comments

Comments
 (0)