Skip to content

Commit e2ad37c

Browse files
committed
Auto-impls: always Ord instead of PartialOrd (can't fail), use twice op< instead of op== and op<
1 parent 6bdcfe4 commit e2ad37c

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

gdnative-core/src/core_types/rid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ impl_basic_traits_as_sys! {
9191
for Rid as godot_rid {
9292
Default => godot_rid_new;
9393
Eq => godot_rid_operator_equal;
94-
PartialOrd => godot_rid_operator_less;
94+
Ord => godot_rid_operator_less;
9595
}
9696
}

gdnative-core/src/core_types/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl_basic_traits_as_sys! {
592592
for StringName as godot_string_name {
593593
Drop => godot_string_name_destroy;
594594
Eq => godot_string_name_operator_equal;
595-
PartialOrd => godot_string_name_operator_less;
595+
Ord => godot_string_name_operator_less;
596596
}
597597
}
598598

gdnative-core/src/core_types/variant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl_basic_traits_as_sys!(
603603
Drop => godot_variant_destroy;
604604
Clone => godot_variant_new_copy;
605605
PartialEq => godot_variant_operator_equal;
606-
PartialOrd => godot_variant_operator_less;
606+
Ord => godot_variant_operator_less;
607607
}
608608
);
609609

gdnative-core/src/macros.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,25 @@ macro_rules! impl_basic_trait_as_sys {
174174
};
175175

176176
(
177-
PartialOrd for $Type:ty as $GdType:ident : $gd_method:ident
177+
Ord for $Type:ty as $GdType:ident : $gd_method:ident
178178
) => {
179179
impl PartialOrd for $Type {
180-
#[inline]
181-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
182-
if self == other {
183-
Some(std::cmp::Ordering::Equal)
184-
} else if unsafe { (get_api().$gd_method)(&self.0, &other.0) } {
185-
Some(std::cmp::Ordering::Less)
186-
} else {
187-
Some(std::cmp::Ordering::Greater)
188-
}
180+
#[inline]
181+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
182+
Some(self.cmp(other))
189183
}
190184
}
191-
};
192-
193-
(
194-
Ord for $Type:ty as $GdType:ident : $gd_method:ident
195-
) => {
196-
impl_basic_trait_as_sys!(PartialOrd for $Type as $GdType : $gd_method);
197185
impl Ord for $Type {
198-
#[inline]
199-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
200-
self.partial_cmp(other).unwrap()
186+
#[inline]
187+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
188+
let op_less = get_api().$gd_method;
189+
if unsafe { op_less(&self.0, &other.0) } {
190+
std::cmp::Ordering::Less
191+
} else if unsafe { op_less(&other.0, &self.0) } {
192+
std::cmp::Ordering::Greater
193+
} else {
194+
std::cmp::Ordering::Equal
195+
}
201196
}
202197
}
203198
};

0 commit comments

Comments
 (0)