Skip to content

Commit f6a8b67

Browse files
committed
Simplify RawGd::is_cast_valid()
1 parent e8a4529 commit f6a8b67

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

godot-core/src/obj/raw_gd.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,8 @@ impl<T: GodotClass> RawGd<T> {
115115
where
116116
U: GodotClass,
117117
{
118-
if self.is_null() {
119-
// Null can be cast to anything.
120-
return true;
121-
}
122-
123-
// SAFETY: object is forgotten below.
124-
let as_obj =
125-
unsafe { self.ffi_cast::<classes::Object>() }.expect("everything inherits Object");
126-
127-
// SAFETY: Object is always a base class.
128-
let cast_is_valid = unsafe { as_obj.as_upcast_ref::<classes::Object>() }
129-
.is_class(&U::class_name().to_gstring());
130-
131-
std::mem::forget(as_obj);
132-
cast_is_valid
118+
self.is_null() // Null can be cast to anything.
119+
|| self.as_object_ref().is_class(&U::class_name().to_gstring())
133120
}
134121

135122
/// Returns `Ok(cast_obj)` on success, `Err(self)` on error

0 commit comments

Comments
 (0)