|
4 | 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -use godot_ffi as sys; |
| 7 | +use crate::builtin::meta::GodotType; |
8 | 8 |
|
9 |
| -pub trait GodotCompatible { |
10 |
| - type Via: GodotType; |
11 |
| -} |
| 9 | +use super::*; |
12 | 10 |
|
13 | 11 | impl<T: GodotCompatible> GodotCompatible for Option<T>
|
14 | 12 | where
|
|
17 | 15 | type Via = Option<T::Via>;
|
18 | 16 | }
|
19 | 17 |
|
20 |
| -pub trait ToGodot: Sized + GodotCompatible { |
21 |
| - fn to_godot(&self) -> Self::Via; |
22 |
| - |
23 |
| - fn into_godot(self) -> Self::Via { |
24 |
| - self.to_godot() |
25 |
| - } |
26 |
| - |
27 |
| - fn to_variant(&self) -> Variant { |
28 |
| - self.to_godot().to_ffi().ffi_to_variant() |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| -pub trait FromGodot: Sized + GodotCompatible { |
33 |
| - // TODO: better error |
34 |
| - fn try_from_godot(via: Self::Via) -> Option<Self>; |
35 |
| - |
36 |
| - fn from_godot(via: Self::Via) -> Self { |
37 |
| - Self::try_from_godot(via).unwrap() |
38 |
| - } |
39 |
| - |
40 |
| - fn try_from_variant(variant: &Variant) -> Result<Self, VariantConversionError> { |
41 |
| - let ffi = <Self::Via as GodotType>::Ffi::ffi_from_variant(variant)?; |
42 |
| - let via = Self::Via::try_from_ffi(ffi).ok_or(VariantConversionError::BadValue)?; |
43 |
| - Self::try_from_godot(via).ok_or(VariantConversionError::BadValue) |
44 |
| - } |
45 |
| - |
46 |
| - fn from_variant(variant: &Variant) -> Self { |
47 |
| - Self::try_from_variant(variant).unwrap() |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 | 18 | impl<T: ToGodot> ToGodot for Option<T>
|
52 | 19 | where
|
53 | 20 | Option<T::Via>: GodotType,
|
|
77 | 44 | }
|
78 | 45 | }
|
79 | 46 |
|
80 |
| -pub(crate) fn into_ffi<T: ToGodot>(t: T) -> <T::Via as GodotType>::Ffi { |
81 |
| - let via = t.into_godot(); |
82 |
| - via.into_ffi() |
83 |
| -} |
84 |
| - |
85 |
| -pub(crate) fn try_from_ffi<T: FromGodot>(ffi: <T::Via as GodotType>::Ffi) -> Option<T> { |
86 |
| - let via = <T::Via as GodotType>::try_from_ffi(ffi)?; |
87 |
| - T::try_from_godot(via) |
88 |
| -} |
89 |
| - |
90 |
| -macro_rules! impl_godot_as_self { |
91 |
| - ($T:ty$(, $param_metadata:expr)?) => { |
92 |
| - impl $crate::builtin::meta::GodotCompatible for $T { |
93 |
| - type Via = $T; |
94 |
| - } |
95 |
| - |
96 |
| - impl $crate::builtin::meta::ToGodot for $T { |
97 |
| - #[inline] |
98 |
| - fn to_godot(&self) -> Self::Via { |
99 |
| - self.clone() |
100 |
| - } |
101 |
| - |
102 |
| - #[inline] |
103 |
| - fn into_godot(self) -> Self::Via { |
104 |
| - self |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - impl $crate::builtin::meta::FromGodot for $T { |
109 |
| - #[inline] |
110 |
| - fn try_from_godot(via: Self::Via) -> Option<Self> { |
111 |
| - Some(via) |
112 |
| - } |
113 |
| - } |
114 |
| - }; |
115 |
| -} |
116 |
| - |
117 |
| -pub(crate) use impl_godot_as_self; |
118 |
| - |
119 |
| -use crate::builtin::{Variant, VariantConversionError}; |
120 |
| - |
121 |
| -use super::{GodotFfiVariant, GodotType}; |
122 |
| - |
123 | 47 | impl GodotCompatible for sys::VariantType {
|
124 | 48 | type Via = i64;
|
125 | 49 | }
|
@@ -193,8 +117,8 @@ impl<T> FromGodot for *const T {
|
193 | 117 | }
|
194 | 118 |
|
195 | 119 | mod scalars {
|
196 |
| - use super::super::GodotType; |
197 | 120 | use super::{impl_godot_as_self, FromGodot, GodotCompatible, ToGodot};
|
| 121 | + use crate::builtin::meta::GodotType; |
198 | 122 | use godot_ffi as sys;
|
199 | 123 |
|
200 | 124 | macro_rules! impl_godot {
|
|
0 commit comments