@@ -330,15 +330,14 @@ fn gen_statements(fields: &Fields, encoding: Encoding, flat: bool) -> syn::Resul
330330 } ;
331331
332332 let value =
333- if cfg ! ( any( feature = "alloc" , feature = "std" ) )
334- && ( field. attrs . borrow ( ) . is_some ( ) || field. index . is_b ( ) )
333+ if ( field. attrs . borrow ( ) . is_some ( ) || field. index . is_b ( ) )
335334 && is_cow ( & field. typ , |t| is_str ( t) || is_byte_slice ( t) )
336335 {
337- if cfg ! ( feature = "std" ) {
338- quote ! ( Some ( std:: borrow:: Cow :: Borrowed ( __v777) ) )
339- } else {
340- quote ! ( Some ( alloc :: borrow :: Cow :: Borrowed ( __v777) ) )
341- }
336+ quote ! ( minicbor :: __minicbor_cfg! {
337+ ' std { Some ( std:: borrow:: Cow :: Borrowed ( __v777) ) }
338+ ' alloc { Some ( alloc :: borrow :: Cow :: Borrowed ( __v777 ) ) }
339+ ' otherwise { Some ( __v777) }
340+ } )
342341 } else {
343342 quote ! ( Some ( __v777) )
344343 } ;
@@ -443,42 +442,41 @@ fn make_transparent_impl
443442 . unwrap_or_else ( || default_decode_fn. clone ( ) ) ;
444443
445444 let decode_call =
446- if cfg ! ( any( feature = "alloc" , feature = "std" ) )
447- && ( field. attrs . borrow ( ) . is_some ( ) || field. index . is_b ( ) )
445+ if ( field. attrs . borrow ( ) . is_some ( ) || field. index . is_b ( ) )
448446 && is_cow ( & field. typ , |t| is_str ( t) || is_byte_slice ( t) )
449447 {
450- let cow =
451- if cfg ! ( feature = "std" ) {
452- quote ! ( std:: borrow:: Cow :: Borrowed ( v) )
453- } else {
454- quote ! ( alloc:: borrow:: Cow :: Borrowed ( v) )
455- } ;
456- if field. is_name {
457- let id = & field. ident ;
458- quote ! {
459- Ok ( #name {
460- #id: match #decode_fn( __d777, __ctx777) {
461- Ok ( v) => #cow,
462- Err ( e) => return Err ( e)
463- }
464- } )
448+ quote ! ( minicbor:: __minicbor_cfg! {
449+ ' std {
450+ match #decode_fn( __d777, __ctx777) {
451+ Ok ( v) => std:: borrow:: Cow :: Borrowed ( v) ,
452+ Err ( e) => return Err ( e)
453+ }
465454 }
466- } else {
467- quote ! {
468- Ok ( #name( match #decode_fn( __d777, __ctx777) {
469- Ok ( v) => #cow,
455+ ' alloc {
456+ match #decode_fn( __d777, __ctx777) {
457+ Ok ( v) => alloc:: borrow:: Cow :: Borrowed ( v) ,
470458 Err ( e) => return Err ( e)
471- } ) )
459+ }
460+ }
461+ ' otherwise {
462+ #decode_fn( __d777, __ctx777) ?
472463 }
464+ } )
465+ } else {
466+ quote ! {
467+ #decode_fn( __d777, __ctx777) ?
473468 }
474- } else if field. is_name {
469+ } ;
470+
471+ let decode_body =
472+ if field. is_name {
475473 let id = & field. ident ;
476474 quote ! {
477- Ok ( #name { #id: #decode_fn ( __d777 , __ctx777 ) ? } )
475+ Ok ( #name { #id: #decode_call } )
478476 }
479477 } else {
480478 quote ! {
481- Ok ( #name( #decode_fn ( __d777 , __ctx777 ) ? ) )
479+ Ok ( #name( #decode_call ) )
482480 }
483481 } ;
484482
@@ -521,7 +519,7 @@ fn make_transparent_impl
521519 Ok ( quote ! {
522520 impl #impl_generics minicbor:: Decode <' bytes, Ctx > for #name #typ_generics #where_clause {
523521 fn decode( __d777: & mut minicbor:: Decoder <' bytes>, __ctx777: & mut Ctx ) -> core:: result:: Result <#name #typ_generics, minicbor:: decode:: Error > {
524- #decode_call
522+ #decode_body
525523 }
526524
527525 #nil_impl
@@ -576,27 +574,25 @@ fn nil(f: &Field) -> proc_macro2::TokenStream {
576574
577575fn decode_tag ( a : & Attributes ) -> proc_macro2:: TokenStream {
578576 if let Some ( t) = a. tag ( ) {
579- let err =
580- if cfg ! ( feature = "std" ) {
581- quote ! {
582- minicbor:: decode:: Error :: tag_mismatch( __t777)
583- . with_message( format!( "expected tag {}" , #t) )
584- . at( __p777)
585- }
586- } else if cfg ! ( feature = "alloc" ) {
587- quote ! {
588- minicbor:: decode:: Error :: tag_mismatch( __t777)
589- . with_message( alloc:: format!( "expected tag {}" , #t) )
590- . at( __p777)
591- }
592- } else {
593- quote ! ( minicbor:: decode:: Error :: tag_mismatch( __t777) . at( __p777) )
594- } ;
595577 quote ! {
596578 let __p777 = __d777. position( ) ;
597579 let __t777 = __d777. tag( ) ?;
598580 if #t != __t777. as_u64( ) {
599- return Err ( #err)
581+ return Err ( minicbor:: __minicbor_cfg! {
582+ ' std {
583+ minicbor:: decode:: Error :: tag_mismatch( __t777)
584+ . with_message( format!( "expected tag {}" , #t) )
585+ . at( __p777)
586+ }
587+ ' alloc {
588+ minicbor:: decode:: Error :: tag_mismatch( __t777)
589+ . with_message( alloc:: format!( "expected tag {}" , #t) )
590+ . at( __p777)
591+ }
592+ ' otherwise {
593+ minicbor:: decode:: Error :: tag_mismatch( __t777) . at( __p777)
594+ }
595+ } ) ;
600596 }
601597 }
602598 } else {
0 commit comments