@@ -2,8 +2,7 @@ extern crate proc_macro;
22
33use proc_macro:: TokenStream ;
44
5- use syn:: parse_macro_input;
6- use syn:: { DeriveInput , ItemImpl } ;
5+ use syn:: { parse, parse_macro_input, DeriveInput , ItemImpl } ;
76
87use args:: { Casts , Flag , Targets } ;
98use gen_caster:: generate_caster;
@@ -46,13 +45,19 @@ mod item_type;
4645/// ```
4746#[ proc_macro_attribute]
4847pub fn cast_to ( args : TokenStream , input : TokenStream ) -> TokenStream {
49- let Targets { flags, paths } = parse_macro_input ! ( args as args:: Targets ) ;
50- let expanded = if paths. is_empty ( ) {
51- item_impl:: process ( & flags, parse_macro_input ! ( input as ItemImpl ) )
52- } else {
53- item_type:: process ( & flags, paths, parse_macro_input ! ( input as DeriveInput ) )
54- } ;
55- expanded. into ( )
48+ match parse :: < Targets > ( args) {
49+ Ok ( Targets { flags, paths } ) => {
50+ if paths. is_empty ( ) {
51+ item_impl:: process ( & flags, parse_macro_input ! ( input as ItemImpl ) )
52+ } else {
53+ item_type:: process ( & flags, paths, parse_macro_input ! ( input as DeriveInput ) )
54+ }
55+ }
56+ Err ( err) => vec ! [ err. to_compile_error( ) , input. into( ) ]
57+ . into_iter ( )
58+ . collect ( ) ,
59+ }
60+ . into ( )
5661}
5762
5863/// Declare target traits for casting implemented by a type.
0 commit comments