Skip to content

Commit 75a36ca

Browse files
authored
Merge pull request #1090 from TitanNano/jovan/const_variant_type
GodotFfi::variant_type can be const
2 parents 7f5191e + 080f124 commit 75a36ca

35 files changed

+44
-112
lines changed

godot-core/src/builtin/aabb.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,7 @@ impl std::fmt::Display for Aabb {
466466
// SAFETY:
467467
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
468468
unsafe impl GodotFfi for Aabb {
469-
fn variant_type() -> sys::VariantType {
470-
sys::VariantType::AABB
471-
}
469+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::AABB;
472470

473471
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
474472
}

godot-core/src/builtin/basis.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,7 @@ impl Mul<Vector3> for Basis {
632632
// SAFETY:
633633
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
634634
unsafe impl GodotFfi for Basis {
635-
fn variant_type() -> sys::VariantType {
636-
sys::VariantType::BASIS
637-
}
635+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::BASIS;
638636

639637
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
640638
}

godot-core/src/builtin/callable.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,7 @@ impl_builtin_traits! {
456456
// The `opaque` in `Callable` is just a pair of pointers, and requires no special initialization or cleanup
457457
// beyond what is done in `from_opaque` and `drop`. So using `*mut Opaque` is safe.
458458
unsafe impl GodotFfi for Callable {
459-
fn variant_type() -> sys::VariantType {
460-
sys::VariantType::CALLABLE
461-
}
459+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::CALLABLE;
462460

463461
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
464462
fn new_from_sys;

godot-core/src/builtin/collections/array.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,7 @@ impl VariantArray {
10331033
// Arrays are properly initialized through a `from_sys` call, but the ref-count should be incremented
10341034
// as that is the callee's responsibility. Which we do by calling `std::mem::forget(array.clone())`.
10351035
unsafe impl<T: ArrayElement> GodotFfi for Array<T> {
1036-
fn variant_type() -> VariantType {
1037-
VariantType::ARRAY
1038-
}
1036+
const VARIANT_TYPE: VariantType = VariantType::ARRAY;
10391037

10401038
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
10411039
}
@@ -1292,9 +1290,9 @@ impl<T: ArrayElement> GodotFfiVariant for Array<T> {
12921290

12931291
fn ffi_from_variant(variant: &Variant) -> Result<Self, ConvertError> {
12941292
// First check if the variant is an array. The array conversion shouldn't be called otherwise.
1295-
if variant.get_type() != Self::variant_type() {
1293+
if variant.get_type() != Self::VARIANT_TYPE {
12961294
return Err(FromVariantError::BadType {
1297-
expected: Self::variant_type(),
1295+
expected: Self::VARIANT_TYPE,
12981296
actual: variant.get_type(),
12991297
}
13001298
.into_error(variant.clone()));

godot-core/src/builtin/collections/dictionary.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ impl Dictionary {
342342
// incremented as that is the callee's responsibility. Which we do by calling
343343
// `std::mem::forget(dictionary.clone())`.
344344
unsafe impl GodotFfi for Dictionary {
345-
fn variant_type() -> sys::VariantType {
346-
sys::VariantType::DICTIONARY
347-
}
345+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::DICTIONARY;
348346

349347
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
350348
}

godot-core/src/builtin/collections/packed_array.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,7 @@ macro_rules! impl_packed_array {
626626
}
627627

628628
unsafe impl GodotFfi for $PackedArray {
629-
fn variant_type() -> sys::VariantType {
630-
sys::VariantType::$VariantType
631-
}
629+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::$VariantType;
632630

633631
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
634632
}

godot-core/src/builtin/color.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ impl Color {
355355
// SAFETY:
356356
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
357357
unsafe impl GodotFfi for Color {
358-
fn variant_type() -> sys::VariantType {
359-
sys::VariantType::COLOR
360-
}
358+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::COLOR;
361359

362360
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
363361
}

godot-core/src/builtin/plane.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ impl Neg for Plane {
265265
// SAFETY:
266266
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
267267
unsafe impl GodotFfi for Plane {
268-
fn variant_type() -> sys::VariantType {
269-
sys::VariantType::PLANE
270-
}
268+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::PLANE;
271269

272270
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self;
273271
fn new_from_sys;

godot-core/src/builtin/projection.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,7 @@ impl GlamConv for Projection {
557557

558558
// SAFETY: This type is represented as `Self` in Godot, so `*mut Self` is sound.
559559
unsafe impl GodotFfi for Projection {
560-
fn variant_type() -> sys::VariantType {
561-
sys::VariantType::PROJECTION
562-
}
560+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::PROJECTION;
563561

564562
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
565563
}

godot-core/src/builtin/quaternion.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,7 @@ impl Mul<Vector3> for Quaternion {
347347
// SAFETY:
348348
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
349349
unsafe impl GodotFfi for Quaternion {
350-
fn variant_type() -> sys::VariantType {
351-
sys::VariantType::QUATERNION
352-
}
350+
const VARIANT_TYPE: sys::VariantType = sys::VariantType::QUATERNION;
353351

354352
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
355353
}

0 commit comments

Comments
 (0)