66
77use proc_macro:: TokenStream ;
88use quote:: quote;
9- use syn:: { parse_macro_input, AttributeArgs , Fields , ItemStruct , Meta , NestedMeta , Path } ;
9+ use syn:: punctuated:: Punctuated ;
10+ use syn:: { parse_macro_input, Fields , ItemStruct , Token , Type } ;
1011
1112/// Implements a newtype to use the [`eventually::aggregate::Root`] instance with
1213/// user-defined [`eventually::aggregate::Aggregate`] types.
@@ -22,7 +23,7 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
2223/// being an example of user-defined `Aggregate` type) outside the `eventually` crate (E0116).
2324/// Therefore, a newtype that uses `aggregate::Root<T>` is required.
2425///
25- /// This attribute macro makes the implementation of a newtype easy, as it Implements
26+ /// This attribute macro makes the implementation of a newtype easy, as it implements
2627/// conversion traits from and to `aggregate::Root<T>` and implements automatic deref
2728/// through [`std::ops::Deref`] and [`std::ops::DerefMut`].
2829///
@@ -31,19 +32,14 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
3132/// This method will panic if the Aggregate Root type is not provided as a macro parameter.
3233#[ proc_macro_attribute]
3334pub fn aggregate_root ( args : TokenStream , item : TokenStream ) -> TokenStream {
34- let args = parse_macro_input ! ( args as AttributeArgs ) ;
3535 let mut item = parse_macro_input ! ( item as ItemStruct ) ;
3636 let item_ident = item. ident . clone ( ) ;
3737
38- let aggregate_type = args
39- . first ( )
40- . and_then ( |meta| match meta {
41- NestedMeta :: Meta ( Meta :: Path ( Path { segments, .. } ) ) => Some ( segments) ,
42- _ => None ,
43- } )
44- . and_then ( |segments| segments. first ( ) )
45- . map ( |segment| segment. ident . clone ( ) )
46- . expect ( "the aggregate root type must be provided as macro parameter" ) ;
38+ let aggregate_type: Type =
39+ parse_macro_input ! ( args with Punctuated :: <Type , Token ![ , ] >:: parse_terminated)
40+ . into_iter ( )
41+ . next ( )
42+ . expect ( "the aggregate root type must be provided as macro parameter" ) ;
4743
4844 item. fields = Fields :: Unnamed (
4945 syn:: parse2 ( quote ! { ( eventually:: aggregate:: Root <#aggregate_type>) } ) . unwrap ( ) ,
0 commit comments