1- use std:: collections:: HashMap ;
1+ use std:: { collections:: HashMap , convert :: TryInto } ;
22
33use ext_php_rs:: {
44 call_user_func, info_table_end, info_table_row, info_table_start, parse_args,
@@ -76,7 +76,7 @@ impl Test {
7676
7777 let result = call_user_func ! ( _fn, "Hello" , 5 ) ;
7878
79- if let Some ( r) = result {
79+ if let Ok ( r) = result {
8080 println ! ( "{}" , r. string( ) . unwrap( ) ) ;
8181 }
8282
@@ -105,37 +105,52 @@ pub extern "C" fn module_init(_type: i32, module_number: i32) -> i32 {
105105
106106 ClassBuilder :: new ( "TestClass" )
107107 . method (
108- FunctionBuilder :: constructor ( Test :: constructor) . build ( ) ,
108+ FunctionBuilder :: constructor ( Test :: constructor)
109+ . build ( )
110+ . expect ( "could not build constructor" ) ,
109111 MethodFlags :: Public ,
110112 )
111113 . method (
112- FunctionBuilder :: new ( "set" , Test :: set) . build ( ) ,
114+ FunctionBuilder :: new ( "set" , Test :: set)
115+ . build ( )
116+ . expect ( "could not build set" ) ,
113117 MethodFlags :: Public ,
114118 )
115119 . method (
116- FunctionBuilder :: new ( "get" , Test :: get) . build ( ) ,
120+ FunctionBuilder :: new ( "get" , Test :: get)
121+ . build ( )
122+ . expect ( "could not build get" ) ,
117123 MethodFlags :: Public ,
118124 )
119125 . method (
120126 FunctionBuilder :: new ( "debug" , Test :: debug)
121127 . arg ( Arg :: new ( "val" , DataType :: Object ) )
122- . build ( ) ,
128+ . build ( )
129+ . expect ( "could not build debug" ) ,
123130 MethodFlags :: Public ,
124131 )
125132 . method (
126133 FunctionBuilder :: new ( "call" , Test :: call)
127134 . arg ( Arg :: new ( "fn" , DataType :: Callable ) )
128- . build ( ) ,
135+ . build ( )
136+ . expect ( "could not build call" ) ,
129137 MethodFlags :: Public ,
130138 )
131139 . property ( "asdf" , "world" , PropertyFlags :: Public )
140+ . expect ( "failed to add asdf property" )
132141 . property ( "jhki" , 12345 , PropertyFlags :: Public )
142+ . expect ( "failed to add jhki property" )
133143 . constant ( "TEST" , "Hello world" )
144+ . expect ( "failed to add test constant" )
134145 . object_override :: < Test > ( )
135- . build ( ) ;
146+ . build ( )
147+ . expect ( "failed to build TestClass" ) ;
136148
137- "Test constant" . register_constant ( "SKEL_TEST_CONST" , module_number) ;
138- 1234 . register_constant ( "SKEL_TEST_LONG_CONST" , module_number) ;
149+ "Test constant"
150+ . register_constant ( "SKEL_TEST_CONST" , module_number)
151+ . expect ( "failed to add skel test const" ) ;
152+ 1234 . register_constant ( "SKEL_TEST_LONG_CONST" , module_number)
153+ . expect ( "failed to add skel test long const" ) ;
139154
140155 0
141156}
@@ -148,20 +163,24 @@ pub extern "C" fn get_module() -> *mut ext_php_rs::php::module::ModuleEntry {
148163 . not_required ( )
149164 . arg ( Arg :: new ( "c" , DataType :: Double ) )
150165 . returns ( DataType :: String , false , false )
151- . build ( ) ;
166+ . build ( )
167+ . expect ( "failed to build sheleton_version" ) ;
152168
153169 let array = FunctionBuilder :: new ( "skel_array" , skeleton_array)
154170 . arg ( Arg :: new ( "arr" , DataType :: Array ) )
155- . build ( ) ;
171+ . build ( )
172+ . expect ( "failed to build skel_array" ) ;
156173
157174 let t = FunctionBuilder :: new ( "test_array" , test_array)
158175 . returns ( DataType :: Array , false , false )
159- . build ( ) ;
176+ . build ( )
177+ . expect ( "failed to build test_array" ) ;
160178
161179 let iter = FunctionBuilder :: new ( "skel_unpack" , skel_unpack)
162180 . arg ( Arg :: new ( "arr" , DataType :: String ) )
163181 . returns ( DataType :: String , false , false )
164- . build ( ) ;
182+ . build ( )
183+ . expect ( "failed to build skel_unpack" ) ;
165184
166185 ModuleBuilder :: new ( "ext-skel" , "0.1.0" )
167186 . info_function ( php_module_info)
@@ -171,6 +190,7 @@ pub extern "C" fn get_module() -> *mut ext_php_rs::php::module::ModuleEntry {
171190 . function ( t)
172191 . function ( iter)
173192 . build ( )
193+ . expect ( "failed to build module" )
174194 . into_raw ( )
175195}
176196
@@ -182,7 +202,7 @@ pub extern "C" fn skeleton_version(execute_data: &mut ExecutionData, retval: &mu
182202
183203 parse_args ! ( execute_data, x, y; z) ;
184204 dbg ! ( x) ;
185- retval. set_string ( "Hello" ) ;
205+ retval. set_string ( "Hello" , false ) ;
186206}
187207
188208#[ no_mangle]
@@ -201,13 +221,18 @@ pub extern "C" fn skeleton_array(execute_data: &mut ExecutionData, _retval: &mut
201221 }
202222
203223 let mut new = ZendHashTable :: new ( ) ;
204- new. insert ( "Hello" , "WOrld" ) ;
224+ new. insert ( "Hello" , "WOrld" )
225+ . expect ( "couldnt insert into hashtable" ) ;
205226 let _ = _retval. set_array ( new) ;
206227}
207228
208229#[ no_mangle]
209230pub extern "C" fn test_array ( _execute_data : & mut ExecutionData , retval : & mut Zval ) {
210- retval. set_array ( vec ! [ 1 , 2 , 3 , 4 ] ) ;
231+ retval. set_array (
232+ vec ! [ 1 , 2 , 3 , 4 ]
233+ . try_into ( )
234+ . expect ( "failed to convert vec to hashtable" ) ,
235+ ) ;
211236}
212237
213238pub extern "C" fn skel_unpack ( execute_data : & mut ExecutionData , retval : & mut Zval ) {
0 commit comments