@@ -7,7 +7,8 @@ pub(crate) struct SettingsBuilder {
77 ident : Ident ,
88 type_name : String ,
99 sort_key_prefix : Option < String > ,
10- partition_key : Option < String > ,
10+ sort_key_field : Option < String > ,
11+ partition_key_field : Option < String > ,
1112 protected_attributes : Vec < String > ,
1213 unprotected_attributes : Vec < String > ,
1314 skipped_attributes : Vec < String > ,
@@ -33,7 +34,8 @@ impl SettingsBuilder {
3334 ident : input. ident . clone ( ) ,
3435 type_name,
3536 sort_key_prefix : None ,
36- partition_key : None ,
37+ sort_key_field : None ,
38+ partition_key_field : None ,
3739 protected_attributes : Vec :: new ( ) ,
3840 unprotected_attributes : Vec :: new ( ) ,
3941 skipped_attributes : Vec :: new ( ) ,
@@ -92,6 +94,48 @@ impl SettingsBuilder {
9294
9395 // Parse the meta for the field
9496 for attr in & field. attrs {
97+ if attr. path ( ) . is_ident ( "sort_key" ) {
98+ let field_name = ident
99+ . as_ref ( )
100+ . ok_or_else ( || {
101+ syn:: Error :: new_spanned (
102+ field,
103+ "internal error: identifier was not Some" ,
104+ )
105+ } ) ?
106+ . to_string ( ) ;
107+
108+ if let Some ( f) = & self . sort_key_field {
109+ return Err ( syn:: Error :: new_spanned (
110+ field,
111+ format ! ( "sort key was already specified to be '{f}'" ) ,
112+ ) ) ;
113+ }
114+
115+ self . sort_key_field = Some ( field_name) ;
116+ }
117+
118+ if attr. path ( ) . is_ident ( "partition_key" ) {
119+ let field_name = ident
120+ . as_ref ( )
121+ . ok_or_else ( || {
122+ syn:: Error :: new_spanned (
123+ field,
124+ "internal error: identifier was not Some" ,
125+ )
126+ } ) ?
127+ . to_string ( ) ;
128+
129+ if let Some ( f) = & self . partition_key_field {
130+ return Err ( syn:: Error :: new_spanned (
131+ field,
132+ format ! ( "partition key was already specified to be '{f}'" ) ,
133+ ) ) ;
134+ }
135+
136+ self . partition_key_field = Some ( field_name) ;
137+ }
138+
95139 if attr. path ( ) . is_ident ( "cryptonamo" ) {
96140 let mut query: Option < ( String , String , Span ) > = None ;
97141 let mut compound_index_name: Option < ( String , Span ) > = None ;
@@ -203,7 +247,8 @@ impl SettingsBuilder {
203247 ident,
204248 type_name,
205249 sort_key_prefix,
206- partition_key,
250+ sort_key_field,
251+ partition_key_field : partition_key,
207252 protected_attributes,
208253 unprotected_attributes,
209254 skipped_attributes,
@@ -222,7 +267,8 @@ impl SettingsBuilder {
222267 Ok ( Settings {
223268 ident,
224269 sort_key_prefix,
225- partition_key : Some ( partition_key) , // TODO: Remove the Some
270+ sort_key_field,
271+ partition_key_field : Some ( partition_key) , // TODO: Remove the Some
226272 protected_attributes,
227273 unprotected_attributes,
228274 skipped_attributes,
@@ -236,7 +282,7 @@ impl SettingsBuilder {
236282 }
237283
238284 pub ( crate ) fn set_partition_key ( & mut self , value : String ) -> Result < ( ) , syn:: Error > {
239- self . partition_key = Some ( value) ;
285+ self . partition_key_field = Some ( value) ;
240286 Ok ( ( ) )
241287 }
242288
0 commit comments