@@ -16,11 +16,9 @@ pub fn wrap(input: syn::Path) -> Result<TokenStream> {
1616 bail ! ( input => "Pass a PHP function name into `wrap_function!()`." ) ;
1717 } ;
1818 let builder_func = format_ident ! ( "_internal_{func_name}" ) ;
19- let err = format ! ( "Failed to build function `{}`." , func_name) ;
2019
2120 Ok ( quote ! { {
2221 ( <#builder_func as :: ext_php_rs:: internal:: function:: PhpFunction >:: FUNCTION_ENTRY ) ( )
23- . expect( #err)
2422 } } )
2523}
2624
@@ -165,7 +163,7 @@ impl<'a> Function<'a> {
165163 . variadic( )
166164 }
167165 } ) ;
168- let output = self . output . as_ref ( ) . map ( |output| {
166+ let returns = self . output . as_ref ( ) . map ( |output| {
169167 quote ! {
170168 . returns(
171169 <#output as :: ext_php_rs:: convert:: IntoZval >:: TYPE ,
@@ -232,6 +230,15 @@ impl<'a> Function<'a> {
232230 }
233231 } ;
234232
233+ let docs = if !self . docs . is_empty ( ) {
234+ let docs = & self . docs ;
235+ quote ! {
236+ . docs( & [ #( #docs) , * ] )
237+ }
238+ } else {
239+ quote ! { }
240+ } ;
241+
235242 Ok ( quote ! {
236243 :: ext_php_rs:: builders:: FunctionBuilder :: new( #name, {
237244 :: ext_php_rs:: zend_fastcall! {
@@ -258,7 +265,8 @@ impl<'a> Function<'a> {
258265 . not_required( )
259266 #( . arg( #not_required_args) ) *
260267 #variadic
261- #output
268+ #returns
269+ #docs
262270 } )
263271 }
264272
@@ -273,13 +281,10 @@ impl<'a> Function<'a> {
273281 struct #internal_ident;
274282
275283 impl :: ext_php_rs:: internal:: function:: PhpFunction for #internal_ident {
276- const FUNCTION_ENTRY : fn ( ) -> :: ext_php_rs:: error:: Result <
277- :: ext_php_rs:: zend:: FunctionEntry
278- > = {
279- fn entry( ) -> :: ext_php_rs:: error:: Result <
280- :: ext_php_rs:: zend:: FunctionEntry
281- > {
282- #builder. build( )
284+ const FUNCTION_ENTRY : fn ( ) -> :: ext_php_rs:: builders:: FunctionBuilder <' static > = {
285+ fn entry( ) -> :: ext_php_rs:: builders:: FunctionBuilder <' static >
286+ {
287+ #builder
283288 }
284289 entry
285290 } ;
@@ -355,14 +360,14 @@ impl<'a> Function<'a> {
355360
356361#[ derive( Debug ) ]
357362pub struct ReceiverArg {
358- pub mutable : bool ,
363+ pub _mutable : bool ,
359364 pub span : Span ,
360365}
361366
362367#[ derive( Debug ) ]
363368pub struct TypedArg < ' a > {
364369 pub name : & ' a Ident ,
365- pub ty : Box < Type > ,
370+ pub ty : Type ,
366371 pub nullable : bool ,
367372 pub default : Option < Lit > ,
368373 pub as_ref : bool ,
@@ -393,7 +398,7 @@ impl<'a> Args<'a> {
393398 bail ! ( receiver => "Too many receivers specified." )
394399 }
395400 result. receiver . replace ( ReceiverArg {
396- mutable : receiver. mutability . is_some ( ) ,
401+ _mutable : receiver. mutability . is_some ( ) ,
397402 span : receiver. span ( ) ,
398403 } ) ;
399404 }
@@ -421,8 +426,8 @@ impl<'a> Args<'a> {
421426 Ok ( result)
422427 }
423428
424- fn parse_typed ( ty : & Box < Type > ) -> ( bool , bool , Box < Type > ) {
425- match ty. as_ref ( ) {
429+ fn parse_typed ( ty : & Type ) -> ( bool , bool , Type ) {
430+ match ty {
426431 Type :: Reference ( ref_) => {
427432 let as_ref = ref_. mutability . is_some ( ) ;
428433 match ref_. elem . as_ref ( ) {
@@ -448,7 +453,7 @@ impl<'a> Args<'a> {
448453 args. args
449454 . iter ( )
450455 . find ( |arg| matches ! ( arg, GenericArgument :: Type ( _) ) )
451- . map ( |ga| match ga {
456+ . and_then ( |ga| match ga {
452457 GenericArgument :: Type ( ty) => Some ( match ty {
453458 Type :: Reference ( r) => {
454459 let mut new_ref = r. clone ( ) ;
@@ -460,11 +465,9 @@ impl<'a> Args<'a> {
460465 } ) ,
461466 _ => None ,
462467 } )
463- . flatten ( )
464468 } else {
465469 None
466470 }
467- . map ( |ty| Box :: new ( ty) )
468471 } )
469472 . unwrap_or_else ( || ty. clone ( ) ) ;
470473 ( false , as_ref, ty. clone ( ) )
@@ -503,10 +506,10 @@ impl<'a> Args<'a> {
503506 }
504507}
505508
506- impl < ' a > TypedArg < ' a > {
509+ impl TypedArg < ' _ > {
507510 /// Returns a 'clean type' with the lifetimes removed. This allows the type
508511 /// to be used outside of the original function context.
509- fn clean_ty ( & self ) -> Box < Type > {
512+ fn clean_ty ( & self ) -> Type {
510513 let mut ty = self . ty . clone ( ) ;
511514 ty. drop_lifetimes ( ) ;
512515 ty
@@ -532,17 +535,18 @@ impl<'a> TypedArg<'a> {
532535 } else {
533536 None
534537 } ;
535- let default = self . default . as_ref ( ) . map ( |_| {
538+ let default = self . default . as_ref ( ) . map ( |val| {
539+ let val = val. to_token_stream ( ) . to_string ( ) ;
536540 quote ! {
537- . default ( )
541+ . default ( #val )
538542 }
539543 } ) ;
540544 let as_ref = if self . as_ref {
541545 Some ( quote ! { . as_ref( ) } )
542546 } else {
543547 None
544548 } ;
545- let variadic = self . variadic . then ( || quote ! { . ir_variadic ( ) } ) ;
549+ let variadic = self . variadic . then ( || quote ! { . is_variadic ( ) } ) ;
546550 Ok ( quote ! {
547551 :: ext_php_rs:: args:: Arg :: new( #name, <#ty as :: ext_php_rs:: convert:: FromZvalMut >:: TYPE )
548552 #null
@@ -595,7 +599,7 @@ pub fn type_is_nullable(ty: &Type, has_default: bool) -> Result<bool> {
595599 . path
596600 . segments
597601 . iter ( )
598- . last ( )
602+ . next_back ( )
599603 . map ( |seg| seg. ident == "Option" )
600604 . unwrap_or ( false )
601605 }
0 commit comments