Skip to content

Commit 101fab1

Browse files
committed
update AsSystemLabel trait
* Updated it to return a `LabelId` directly. * yeeted the associated type.
1 parent afe5d02 commit 101fab1

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
world::{World, WorldId},
1313
};
1414
use bevy_ecs_macros::all_tuples;
15-
use std::{borrow::Cow, fmt::Debug, hash::Hash, marker::PhantomData};
15+
use std::{borrow::Cow, fmt::Debug, marker::PhantomData};
1616

1717
/// The metadata of a [`System`].
1818
#[derive(Clone)]
@@ -452,41 +452,28 @@ where
452452
/// A [`SystemLabel`] that was automatically generated for a system on the basis of its `TypeId`.
453453
pub struct SystemTypeIdLabel<T: 'static>(PhantomData<fn() -> T>);
454454

455+
impl<T: 'static> SystemLabel for SystemTypeIdLabel<T> {
456+
#[inline]
457+
fn as_str(&self) -> &'static str {
458+
std::any::type_name::<T>()
459+
}
460+
}
461+
455462
impl<T> Debug for SystemTypeIdLabel<T> {
456463
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
457464
f.debug_tuple("SystemTypeIdLabel")
458465
.field(&std::any::type_name::<T>())
459466
.finish()
460467
}
461468
}
462-
impl<T> Hash for SystemTypeIdLabel<T> {
463-
fn hash<H: std::hash::Hasher>(&self, _state: &mut H) {
464-
// All SystemTypeIds of a given type are the same.
465-
}
466-
}
469+
467470
impl<T> Clone for SystemTypeIdLabel<T> {
468471
fn clone(&self) -> Self {
469-
Self(PhantomData)
472+
*self
470473
}
471474
}
472-
473475
impl<T> Copy for SystemTypeIdLabel<T> {}
474476

475-
impl<T> PartialEq for SystemTypeIdLabel<T> {
476-
#[inline]
477-
fn eq(&self, _other: &Self) -> bool {
478-
// All labels of a given type are equal, as they will all have the same type id
479-
true
480-
}
481-
}
482-
impl<T> Eq for SystemTypeIdLabel<T> {}
483-
484-
impl<T> SystemLabel for SystemTypeIdLabel<T> {
485-
fn as_str(&self) -> &'static str {
486-
std::any::type_name::<T>()
487-
}
488-
}
489-
490477
/// A trait implemented for all functions that can be used as [`System`]s.
491478
///
492479
/// This trait can be useful for making your own systems which accept other systems,
@@ -612,24 +599,21 @@ all_tuples!(impl_system_function, 0, 16, F);
612599
/// Used to implicitly convert systems to their default labels. For example, it will convert
613600
/// "system functions" to their [`SystemTypeIdLabel`].
614601
pub trait AsSystemLabel<Marker> {
615-
type SystemLabel: SystemLabel;
616-
fn as_system_label(&self) -> Self::SystemLabel;
602+
fn as_system_label(&self) -> SystemLabelId;
617603
}
618604

619605
impl<In, Out, Param: SystemParam, Marker, T: SystemParamFunction<In, Out, Param, Marker>>
620606
AsSystemLabel<(In, Out, Param, Marker)> for T
621607
{
622-
type SystemLabel = SystemTypeIdLabel<Self>;
623-
624-
fn as_system_label(&self) -> Self::SystemLabel {
625-
SystemTypeIdLabel(PhantomData::<fn() -> Self>)
608+
#[inline]
609+
fn as_system_label(&self) -> SystemLabelId {
610+
SystemTypeIdLabel::<T>(PhantomData).as_label()
626611
}
627612
}
628613

629-
impl<T: SystemLabel + Clone> AsSystemLabel<()> for T {
630-
type SystemLabel = T;
631-
632-
fn as_system_label(&self) -> Self::SystemLabel {
633-
self.clone()
614+
impl<T: SystemLabel> AsSystemLabel<()> for T {
615+
#[inline]
616+
fn as_system_label(&self) -> SystemLabelId {
617+
self.as_label()
634618
}
635619
}

0 commit comments

Comments
 (0)