@@ -21,6 +21,16 @@ pub enum LuaMessage {
2121 Variadic ( VariadicLuaMessage ) ,
2222}
2323
24+ impl LuaMessage {
25+ pub fn from_slice < I : IntoIterator < Item = impl Into < LuaMessage > > > ( iter : I ) -> Self {
26+ LuaMessage :: from (
27+ iter. into_iter ( )
28+ . map ( |v| v. into ( ) )
29+ . collect :: < Vec < LuaMessage > > ( ) ,
30+ )
31+ }
32+ }
33+
2434impl From < bool > for LuaMessage {
2535 fn from ( s : bool ) -> Self {
2636 LuaMessage :: Boolean ( s)
@@ -79,16 +89,87 @@ impl PartialEq<VariadicLuaMessage> for VariadicLuaMessage {
7989 }
8090}
8191
92+ impl From < VariadicLuaMessage > for LuaMessage {
93+ fn from ( s : VariadicLuaMessage ) -> Self {
94+ LuaMessage :: from ( s. 0 )
95+ }
96+ }
8297impl From < Variadic < LuaMessage > > for LuaMessage {
8398 fn from ( s : Variadic < LuaMessage > ) -> Self {
84- LuaMessage :: from (
85- s. into_iter ( )
86- . map ( |v| LuaMessage :: from ( v. clone ( ) ) )
87- . collect :: < Vec < LuaMessage > > ( ) ,
88- )
99+ LuaMessage :: from ( s. into_iter ( ) . map ( |v| v) . collect :: < Vec < LuaMessage > > ( ) )
89100 }
90101}
91102
103+ macro_rules! lua_message_convert_from_collection {
104+ ( $x: tt, $y: ty) => {
105+ impl From <$x<$y>> for LuaMessage {
106+ fn from( s: $x<$y>) -> Self {
107+ LuaMessage :: from(
108+ s. into_iter( )
109+ . map( |v| LuaMessage :: from( v) )
110+ . collect:: <Vec <LuaMessage >>( ) ,
111+ )
112+ }
113+ }
114+ impl From <$x<$y>> for MultiLuaMessage {
115+ fn from( s: $x<$y>) -> Self {
116+ LuaMessage :: from( s) . into( )
117+ }
118+ }
119+ } ;
120+ }
121+ macro_rules! lua_message_convert_from_collection_option {
122+ ( $x: tt, $y: ty) => {
123+ impl From <$x<Option <$y>>> for LuaMessage {
124+ fn from( s: $x<Option <$y>>) -> Self {
125+ LuaMessage :: from(
126+ s. into_iter( )
127+ . map( |v| match v {
128+ Some ( s) => LuaMessage :: from( s) ,
129+ None => LuaMessage :: Nil ,
130+ } )
131+ . collect:: <Vec <LuaMessage >>( ) ,
132+ )
133+ }
134+ }
135+ impl From <$x<Option <$y>>> for MultiLuaMessage {
136+ fn from( s: $x<Option <$y>>) -> Self {
137+ LuaMessage :: from( s) . into( )
138+ }
139+ }
140+ } ;
141+ }
142+ macro_rules! lua_message_convert_from_collection_and_types {
143+ ( $y: ty) => {
144+ lua_message_convert_from_collection!( Vec , $y) ;
145+ lua_message_convert_from_collection!( Variadic , $y) ;
146+ lua_message_convert_from_collection_option!( Vec , $y) ;
147+ lua_message_convert_from_collection_option!( Variadic , $y) ;
148+ impl From <$y> for MultiLuaMessage {
149+ fn from( s: $y) -> Self {
150+ LuaMessage :: from( s) . into( )
151+ }
152+ }
153+ } ;
154+ }
155+ lua_message_convert_from_collection_and_types ! ( String ) ;
156+ lua_message_convert_from_collection_and_types ! ( bool ) ;
157+ lua_message_convert_from_collection_and_types ! ( i8 ) ;
158+ lua_message_convert_from_collection_and_types ! ( u8 ) ;
159+ lua_message_convert_from_collection_and_types ! ( i16 ) ;
160+ lua_message_convert_from_collection_and_types ! ( u16 ) ;
161+ lua_message_convert_from_collection_and_types ! ( i32 ) ;
162+ lua_message_convert_from_collection_and_types ! ( u32 ) ;
163+ lua_message_convert_from_collection_and_types ! ( i64 ) ;
164+ lua_message_convert_from_collection_and_types ! ( isize ) ;
165+ lua_message_convert_from_collection_and_types ! ( usize ) ;
166+ lua_message_convert_from_collection_and_types ! ( f32 ) ;
167+ lua_message_convert_from_collection_and_types ! ( f64 ) ;
168+ lua_message_convert_from_collection_and_types ! ( HashMap <String , LuaMessage >) ;
169+ // lua_message_convert_from_collection_and_types!(Vec<LuaMessage>);
170+ // lua_message_convert_from_collection_and_types!(VariadicLuaMessage);
171+ // lua_message_convert_from_collection_and_types!(Variadic<LuaMessage>);
172+
92173impl Into < Variadic < LuaMessage > > for LuaMessage {
93174 fn into ( self ) -> Variadic < LuaMessage > {
94175 return Variadic :: from_iter ( [ self ] ) ;
@@ -213,6 +294,13 @@ impl FromIterator<LuaMessage> for LuaMessage {
213294 LuaMessage :: Array ( Vec :: < LuaMessage > :: from_iter ( iter) )
214295 }
215296}
297+ /*
298+ impl<I: IntoIterator<Item = LuaMessage>> From<I> for LuaMessage {
299+ fn from(s: I) -> Self {
300+ LuaMessage::Array(Vec::<LuaMessage>::from_iter(s))
301+ }
302+ }
303+ // */
216304impl From < LuaMessage > for Option < Vec < LuaMessage > > {
217305 fn from ( s : LuaMessage ) -> Self {
218306 match s {
@@ -293,6 +381,17 @@ impl<'lua> ToLua<'lua> for LuaMessage {
293381#[ derive( Debug , PartialEq , Clone ) ]
294382pub struct MultiLuaMessage ( LuaMessage ) ;
295383
384+ impl MultiLuaMessage {
385+ pub fn from_slice < I : IntoIterator < Item = impl Into < LuaMessage > > > ( iter : I ) -> Self {
386+ LuaMessage :: Variadic ( VariadicLuaMessage (
387+ iter. into_iter ( )
388+ . map ( |v| v. into ( ) )
389+ . collect :: < Variadic < LuaMessage > > ( ) ,
390+ ) )
391+ . into ( )
392+ }
393+ }
394+
296395impl < ' lua > ToLuaMulti < ' lua > for MultiLuaMessage {
297396 fn to_lua_multi ( self , lua : Context < ' lua > ) -> LuaResult < MultiValue < ' lua > > {
298397 match self . 0 {
0 commit comments