Skip to content

Commit c985e7f

Browse files
fix example
1 parent 6245c93 commit c985e7f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

examples/ecs/component_hooks.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ fn setup(world: &mut World) {
7575
let value = world.get::<MyComponent>(entity).unwrap().0;
7676
println!(
7777
"{component_id:?} added to {entity:?} with value {value:?}{}",
78-
caller.map(|location| format!("due to {location}").unwrap_or_default())
78+
caller
79+
.map(|location| format!("due to {location}"))
80+
.unwrap_or_default()
7981
);
8082
// Or access resources
8183
world
@@ -102,7 +104,9 @@ fn setup(world: &mut World) {
102104
let value = world.get::<MyComponent>(entity).unwrap().0;
103105
println!(
104106
"{component_id:?} removed from {entity:?} with value {value:?}{}",
105-
caller.map(|location| format!("due to {location}").unwrap_or_default())
107+
caller
108+
.map(|location| format!("due to {location}"))
109+
.unwrap_or_default()
106110
);
107111
// You can also issue commands through `.commands()`
108112
world.commands().entity(entity).despawn();

examples/ecs/immutable_components.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy::{
1010
utils::HashMap,
1111
};
1212
use core::alloc::Layout;
13+
use core::panic::Location;
1314

1415
/// This component is mutable, the default case. This is indicated by components
1516
/// implementing [`Component`] where [`Component::Mutability`] is [`Mutable`](bevy::ecs::component::Mutable).
@@ -73,7 +74,12 @@ impl NameIndex {
7374
///
7475
/// Since all mutations to [`Name`] are captured by hooks, we know it is not currently
7576
/// inserted in the index, and its value will not change without triggering a hook.
76-
fn on_insert_name(mut world: DeferredWorld<'_>, entity: Entity, _component: ComponentId) {
77+
fn on_insert_name(
78+
mut world: DeferredWorld<'_>,
79+
entity: Entity,
80+
_component: ComponentId,
81+
_caller: Option<&'static Location<'static>>,
82+
) {
7783
let Some(&name) = world.entity(entity).get::<Name>() else {
7884
unreachable!("OnInsert hook guarantees `Name` is available on entity")
7985
};
@@ -88,7 +94,12 @@ fn on_insert_name(mut world: DeferredWorld<'_>, entity: Entity, _component: Comp
8894
///
8995
/// Since all mutations to [`Name`] are captured by hooks, we know it is currently
9096
/// inserted in the index.
91-
fn on_replace_name(mut world: DeferredWorld<'_>, entity: Entity, _component: ComponentId) {
97+
fn on_replace_name(
98+
mut world: DeferredWorld<'_>,
99+
entity: Entity,
100+
_component: ComponentId,
101+
_caller: Option<&'static Location<'static>>,
102+
) {
92103
let Some(&name) = world.entity(entity).get::<Name>() else {
93104
unreachable!("OnReplace hook guarantees `Name` is available on entity")
94105
};

0 commit comments

Comments
 (0)