Skip to content

Commit fd22cf5

Browse files
committed
Add Inherits::IS_SAME_CLASS
1 parent a03ecc5 commit fd22cf5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

godot-core/src/obj/traits.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,18 @@ unsafe impl Bounds for NoBase {
134134
/// This trait must only be implemented for subclasses of `Base`.
135135
///
136136
/// Importantly, this means it is always safe to upcast a value of type `Gd<Self>` to `Gd<Base>`.
137-
pub unsafe trait Inherits<Base: GodotClass>: GodotClass {}
137+
pub unsafe trait Inherits<Base: GodotClass>: GodotClass {
138+
/// True iff `Self == Base`.
139+
///
140+
/// Exists because something like C++'s [`std::is_same`](https://en.cppreference.com/w/cpp/types/is_same.html) is notoriously difficult
141+
/// in stable Rust, due to lack of specialization.
142+
const IS_SAME_CLASS: bool = false;
143+
}
138144

139145
// SAFETY: Every class is a subclass of itself.
140-
unsafe impl<T: GodotClass> Inherits<T> for T {}
146+
unsafe impl<T: GodotClass> Inherits<T> for T {
147+
const IS_SAME_CLASS: bool = true;
148+
}
141149

142150
/// Trait that defines a `T` -> `dyn Trait` relation for use in [`DynGd`][crate::obj::DynGd].
143151
///

0 commit comments

Comments
 (0)