Skip to content

Commit 37c1360

Browse files
committed
Workaround Eq/Ord bug for older Godot versions (fixed upstream meanwhile)
1 parent 3e63a35 commit 37c1360

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

gdnative-core/src/core_types/string.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,36 @@ impl StringName {
592592
impl_basic_traits_as_sys! {
593593
for StringName as godot_string_name {
594594
Drop => godot_string_name_destroy;
595-
Eq => godot_string_name_operator_equal;
596-
Ord => godot_string_name_operator_less;
595+
596+
// Note: Godot's equal/less implementations contained a bug until Godot 3.5, see https://github.com/godot-rust/godot-rust/pull/912
597+
// Thus explicit impl as a workaround for now
598+
// Eq => godot_string_name_operator_equal;
599+
// Ord => godot_string_name_operator_less;
600+
}
601+
}
602+
603+
impl PartialEq for StringName {
604+
#[inline]
605+
fn eq(&self, other: &Self) -> bool {
606+
// Slow but correct -- see comment above
607+
self.to_godot_string() == other.to_godot_string()
608+
}
609+
}
610+
611+
impl Eq for StringName {}
612+
613+
impl PartialOrd for StringName {
614+
#[inline]
615+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
616+
Some(Ord::cmp(self, other))
617+
}
618+
}
619+
620+
impl Ord for StringName {
621+
#[inline]
622+
fn cmp(&self, other: &Self) -> Ordering {
623+
// Slow but correct -- see comment above
624+
Ord::cmp(&self.to_godot_string(), &other.to_godot_string())
597625
}
598626
}
599627

0 commit comments

Comments
 (0)