@@ -25,12 +25,89 @@ use crate::builtin::*;
25
25
use crate :: engine:: global;
26
26
use registration:: method:: MethodParamOrReturnInfo ;
27
27
28
+ /// Conversion of GodotFfi-types into/from [`Variant`].
28
29
pub trait GodotFfiVariant : Sized + GodotFfi {
29
30
fn ffi_to_variant ( & self ) -> Variant ;
30
31
fn ffi_from_variant ( variant : & Variant ) -> Result < Self , VariantConversionError > ;
31
32
}
32
33
33
- pub trait GodotType : GodotCompatible < Via = Self > + ToGodot + FromGodot {
34
+ mod sealed {
35
+ // To ensure the user does not implement `GodotType` for their own types.
36
+
37
+ use godot_ffi:: GodotNullableFfi ;
38
+
39
+ use super :: GodotType ;
40
+ use crate :: builtin:: * ;
41
+ use crate :: obj:: * ;
42
+
43
+ pub trait Sealed { }
44
+
45
+ impl Sealed for Aabb { }
46
+ impl Sealed for Basis { }
47
+ impl Sealed for Callable { }
48
+ impl Sealed for Vector2 { }
49
+ impl Sealed for Vector3 { }
50
+ impl Sealed for Vector4 { }
51
+ impl Sealed for Vector2i { }
52
+ impl Sealed for Vector3i { }
53
+ impl Sealed for Vector4i { }
54
+ impl Sealed for Quaternion { }
55
+ impl Sealed for Color { }
56
+ impl Sealed for GodotString { }
57
+ impl Sealed for StringName { }
58
+ impl Sealed for NodePath { }
59
+ impl Sealed for PackedByteArray { }
60
+ impl Sealed for PackedInt32Array { }
61
+ impl Sealed for PackedInt64Array { }
62
+ impl Sealed for PackedFloat32Array { }
63
+ impl Sealed for PackedFloat64Array { }
64
+ impl Sealed for PackedStringArray { }
65
+ impl Sealed for PackedVector2Array { }
66
+ impl Sealed for PackedVector3Array { }
67
+ impl Sealed for PackedColorArray { }
68
+ impl Sealed for Plane { }
69
+ impl Sealed for Projection { }
70
+ impl Sealed for Rid { }
71
+ impl Sealed for Rect2 { }
72
+ impl Sealed for Rect2i { }
73
+ impl Sealed for Signal { }
74
+ impl Sealed for Transform2D { }
75
+ impl Sealed for Transform3D { }
76
+ impl Sealed for Dictionary { }
77
+ impl Sealed for bool { }
78
+ impl Sealed for i64 { }
79
+ impl Sealed for i32 { }
80
+ impl Sealed for i16 { }
81
+ impl Sealed for i8 { }
82
+ impl Sealed for u64 { }
83
+ impl Sealed for u32 { }
84
+ impl Sealed for u16 { }
85
+ impl Sealed for u8 { }
86
+ impl Sealed for f64 { }
87
+ impl Sealed for f32 { }
88
+ impl Sealed for ( ) { }
89
+ impl Sealed for Variant { }
90
+ impl < T : GodotType > Sealed for Array < T > { }
91
+ impl < T : GodotClass > Sealed for RawGd < T > { }
92
+ impl < T : GodotClass > Sealed for Gd < T > { }
93
+ impl < T > Sealed for Option < T >
94
+ where
95
+ T : GodotType ,
96
+ T :: Ffi : GodotNullableFfi ,
97
+ {
98
+ }
99
+ }
100
+
101
+ /// Types that can represent some Godot type.
102
+ ///
103
+ /// This trait cannot be implemented for custom user types, for that you should see [`GodotCompatible`]
104
+ /// instead.
105
+ ///
106
+ /// Unlike [`GodotFfi`], types implementing this trait don't need to fully represent its corresponding Godot
107
+ /// type. For instance [`i32`] does not implement [`GodotFfi`] because it cannot represent all values of
108
+ /// Godot's `int` type, however it does implement `GodotType` because we can set the metadata of values with
109
+ /// this type to indicate that they are 32 bits large.
110
+ pub trait GodotType : GodotCompatible < Via = Self > + ToGodot + FromGodot + sealed:: Sealed {
34
111
type Ffi : GodotFfiVariant ;
35
112
36
113
fn to_ffi ( & self ) -> Self :: Ffi ;
0 commit comments