1
1
//! Implementations of the [`IntoScript`] trait for various types.
2
2
3
3
use std:: { borrow:: Cow , collections:: HashMap , ffi:: OsString , path:: PathBuf } ;
4
-
5
4
use bevy:: reflect:: Reflect ;
6
5
7
6
use crate :: {
8
7
bindings:: { script_value:: ScriptValue , ReflectReference , WorldGuard } ,
9
8
error:: InteropError ,
10
- self_type_dependency_only,
11
9
} ;
12
-
13
10
use super :: {
14
- from:: Val ,
11
+ from:: { Union , Val } ,
15
12
script_function:: { DynamicScriptFunction , DynamicScriptFunctionMut } ,
16
13
} ;
17
14
@@ -35,14 +32,13 @@ impl IntoScript for ScriptValue {
35
32
}
36
33
}
37
34
38
- self_type_dependency_only ! ( ScriptValue ) ;
39
35
40
36
impl IntoScript for ( ) {
41
37
fn into_script ( self , _world : WorldGuard ) -> Result < ScriptValue , InteropError > {
42
38
Ok ( ScriptValue :: Unit )
43
39
}
44
40
}
45
- self_type_dependency_only ! ( ( ) ) ;
41
+
46
42
47
43
impl IntoScript for DynamicScriptFunctionMut {
48
44
fn into_script ( self , _world : WorldGuard ) -> Result < ScriptValue , InteropError > {
@@ -56,14 +52,12 @@ impl IntoScript for DynamicScriptFunction {
56
52
}
57
53
}
58
54
59
- self_type_dependency_only ! ( DynamicScriptFunctionMut , DynamicScriptFunction ) ;
60
55
61
56
impl IntoScript for bool {
62
57
fn into_script ( self , _world : WorldGuard ) -> Result < ScriptValue , InteropError > {
63
58
Ok ( ScriptValue :: Bool ( self ) )
64
59
}
65
60
}
66
- self_type_dependency_only ! ( bool ) ;
67
61
68
62
macro_rules! impl_into_with_downcast {
69
63
( $variant: tt as $cast: ty [ $( $ty: ty) ,* ] ) => {
@@ -80,9 +74,7 @@ macro_rules! impl_into_with_downcast {
80
74
81
75
impl_into_with_downcast ! ( Integer as i64 [ i8 , i16 , i32 , i64 , i128 , u8 , u16 , u32 , u64 , u128 , usize , isize ] ) ;
82
76
impl_into_with_downcast ! ( Float as f64 [ f32 , f64 ] ) ;
83
- self_type_dependency_only ! (
84
- i8 , i16 , i32 , i64 , i128 , u8 , u16 , u32 , u64 , u128 , usize , isize , f32 , f64
85
- ) ;
77
+
86
78
87
79
macro_rules! impl_into_stringlike {
88
80
( $id: ident, [ $( ( $ty: ty => $conversion: expr) ) ,* ] ) => {
@@ -108,15 +100,14 @@ impl_into_stringlike!(
108
100
]
109
101
) ;
110
102
111
- self_type_dependency_only ! ( String , char , PathBuf , OsString ) ;
112
103
113
104
impl IntoScript for & ' static str {
114
105
fn into_script ( self , _world : WorldGuard ) -> Result < ScriptValue , InteropError > {
115
106
Ok ( ScriptValue :: String ( Cow :: Borrowed ( self ) ) )
116
107
}
117
108
}
118
109
119
- self_type_dependency_only ! ( & ' static str ) ;
110
+
120
111
121
112
impl IntoScript for ReflectReference {
122
113
fn into_script ( self , _world : WorldGuard ) -> Result < ScriptValue , InteropError > {
@@ -165,6 +156,15 @@ impl<T: IntoScript, const N: usize> IntoScript for [T; N] {
165
156
}
166
157
}
167
158
159
+ impl < T1 : IntoScript , T2 : IntoScript > IntoScript for Union < T1 , T2 > {
160
+ fn into_script ( self , world : WorldGuard ) -> Result < ScriptValue , InteropError > {
161
+ match self . into_left ( ) {
162
+ Ok ( left) => left. into_script ( world) ,
163
+ Err ( right) => right. into_script ( world) ,
164
+ }
165
+ }
166
+ }
167
+
168
168
impl < V : IntoScript > IntoScript for HashMap < String , V > {
169
169
fn into_script ( self , world : WorldGuard ) -> Result < ScriptValue , InteropError > {
170
170
let mut map = HashMap :: new ( ) ;
0 commit comments