Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions crates/bevy_ecs/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
/// [`Name`] should not be treated as a globally unique identifier for entities,
/// as multiple entities can have the same name. [`Entity`] should be
/// used instead as the default unique identifier.
#[derive(Component, Clone)]
#[derive(Component, Clone, PartialEq, Eq)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
Expand All @@ -56,10 +56,18 @@ impl Default for Name {
}

/// A wrapper over Hashed. This exists to make Name("value".into()) possible, which plays nicely with contexts like the `bsn!` macro.
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
pub struct HashedStr(Hashed<Cow<'static, str>>);

impl Deref for HashedStr {
type Target = str;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<&'static str> for HashedStr {
fn from(value: &'static str) -> Self {
Self(Hashed::new(Cow::Borrowed(value)))
Expand Down Expand Up @@ -216,19 +224,6 @@ impl Hash for Name {
}
}

impl PartialEq for Name {
fn eq(&self, other: &Self) -> bool {
if self.0 .0.hash() != other.0 .0.hash() {
// Makes the common case of two strings not been equal very fast
return false;
}

self.0 .0.eq(&other.0 .0)
}
}

impl Eq for Name {}

impl PartialOrd for Name {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
Expand Down
Loading