Skip to content

Commit a532914

Browse files
committed
add methods for checking the type of label IDs
1 parent 6dfa397 commit a532914

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/bevy_app/src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ impl App {
373373
stage_label: impl StageLabel,
374374
system: impl IntoSystemDescriptor<Params>,
375375
) -> &mut Self {
376-
use std::any::TypeId;
376+
let stage_label = stage_label.as_label();
377377
assert!(
378-
stage_label.type_id() != TypeId::of::<StartupStage>(),
378+
!stage_label.is::<StartupStage>(),
379379
"add systems to a startup stage using App::add_startup_system_to_stage"
380380
);
381381
self.schedule.add_system_to_stage(stage_label, system);
@@ -408,9 +408,9 @@ impl App {
408408
stage_label: impl StageLabel,
409409
system_set: SystemSet,
410410
) -> &mut Self {
411-
use std::any::TypeId;
411+
let stage_label = stage_label.as_label();
412412
assert!(
413-
stage_label.type_id() != TypeId::of::<StartupStage>(),
413+
!stage_label.is::<StartupStage>(),
414414
"add system sets to a startup stage using App::add_startup_system_set_to_stage"
415415
);
416416
self.schedule

crates/bevy_utils/src/label.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,15 @@ macro_rules! define_label {
131131
self.data().hash(state);
132132
}
133133
}
134+
135+
impl $id_name {
136+
/// Returns true if this label was constructed from an instance of type `L`.
137+
pub fn is<L: $label_name>(self) -> bool {
138+
// FIXME: This is potentially incorrect, due to the
139+
// compiler unifying identical functions. We'll likely
140+
// have to store some kind of hash of the TypeId.
141+
(self.f as usize) == (<L as $label_name>::fmt as usize)
142+
}
143+
}
134144
};
135145
}

0 commit comments

Comments
 (0)