former_meta 2.43.0

A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Implementation of its derive macro. Should not be used independently, instead use module::former which relies on the module.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
// File: module/core/former_meta/src/derive_former/field_attrs.rs
//! # Field-Level Attribute Processing and Management
//!
//! This module handles the parsing, validation, and processing of all field-level attributes
//! for the Former derive macro. It provides comprehensive support for complex field attribute
//! scenarios and has been extensively tested through the resolution of manual implementation tests.
//!
//! ## Core Functionality
//!
//! ### Supported Field Attributes
//! - `#[ former( ... ) ]` - General field configuration including defaults
//! - `#[ scalar( ... ) ]` - Direct scalar value assignment
//! - `#[ subform_scalar( ... ) ]` - Nested scalar subform construction
//! - `#[ subform_collection( ... ) ]` - Collection subform management
//! - `#[ subform_entry( ... ) ]` - HashMap/Map entry subform handling
//! - `#[ former_ignore ]` - Exclude field from constructor arguments
//!
//! ## Critical Implementation Insights
//!
//! ### Field Attribute Complexity Handling
//! Field attributes are significantly more complex than struct attributes because they must handle :
//! - **Generic Type Parameters** : Field types with complex generic constraints
//! - **Lifetime Parameters** : References and borrowed data in field types
//! - **Collection Type Inference** : Automatic detection of Vec, `HashMap`, `HashSet` patterns
//! - **Subform Nesting** : Recursive Former patterns for complex data structures
//! - **Trait Bound Propagation** : Hash+Eq requirements for `HashMap` keys
//!
//! ### Pitfalls Resolved Through Testing
//!
//! #### 1. Generic Type Parameter Handling
//! **Issue** : Field types with complex generics caused attribute parsing failures
//! **Solution** : Proper `syn ::Type` parsing with full generic parameter preservation
//! **Prevention** : Comprehensive type analysis before attribute application
//!
//! #### 2. Collection Type Detection
//! **Issue** : Collection attributes applied to non-collection types caused compilation errors
//! **Solution** : Type introspection to validate attribute-type compatibility
//! **Prevention** : Early validation of attribute-field type compatibility
//!
//! #### 3. Subform Nesting Complexity
//! **Issue** : Nested subforms with lifetime parameters caused undeclared lifetime errors
//! **Solution** : Proper lifetime parameter propagation through subform hierarchies
//! **Prevention** : Systematic lifetime parameter tracking across subform levels
//!
//! #### 4. Hash+Eq Trait Bound Requirements
//! **Issue** : `HashMap` fields without proper key type trait bounds caused E0277 errors
//! **Solution** : Automatic trait bound detection and application for `HashMap` scenarios
//! **Prevention** : Collection-specific trait bound validation and insertion
//!
//! ## Attribute Processing Architecture
//!
//! ### Processing Flow
//! 1. **Field Type Analysis** : Analyze the field's type for collection patterns and generics
//! 2. **Attribute Parsing** : Parse all field attributes using dedicated parsers
//! 3. **Compatibility Validation** : Ensure attributes are compatible with field type
//! 4. **Generic Propagation** : Propagate generic parameters through attribute configuration
//! 5. **Code Generation Setup** : Prepare attribute information for code generation phase
//!
//! ### Error Handling Strategy
//! - **Type Compatibility** : Early detection of incompatible attribute-type combinations
//! - **Generic Validation** : Validation of generic parameter usage in attributes
//! - **Lifetime Checking** : Verification of lifetime parameter consistency
//! - **Collection Validation** : Specific validation for collection-related attributes
//!
//! ## Performance and Memory Considerations
//! - **Lazy Type Analysis** : Complex type analysis only performed when attributes are present
//! - **Cached Results** : Type introspection results cached to avoid duplicate analysis
//! - **Reference Usage** : Extensive use of references to minimize memory allocation
//! - **Clone Implementation** : Strategic Clone implementation for reuse scenarios

use macro_tools ::
{
  Result,
  AttributeComponent,
  AttributePropertyComponent,
  AttributePropertyOptionalBoolean,
  AttributePropertyOptionalSyn,
  AttributePropertyOptionalSingletone,
  proc_macro2 ::TokenStream,
  syn, return_syn_err, syn_err, qt
};

use component_model_types :: { Assign, OptionExt };

// ==================================
// FieldAttributes Definition
// ==================================

/// Comprehensive field-level attribute container for the Former derive macro.
///
/// This structure aggregates all possible field-level attributes and provides a unified
/// interface for accessing their parsed values. It has been extensively tested through
/// the resolution of complex manual implementation scenarios involving generic types,
/// lifetime parameters, and collection handling.
///
/// # Supported Attribute Categories
///
/// ## Configuration Attributes
/// - **`config`** : General field configuration including default values
/// - **`former_ignore`** : Exclude field from standalone constructor arguments
///
/// ## Setter Type Attributes
/// - **`scalar`** : Direct scalar value assignment (bypasses Former pattern)
/// - **`subform_scalar`** : Nested scalar subform construction
/// - **`subform_collection`** : Collection subform management (Vec, `HashMap`, etc.)
/// - **`subform_entry`** : HashMap/Map entry subform handling
///
/// # Critical Design Decisions
///
/// ## Attribute Mutual Exclusivity
/// Only one setter type attribute should be specified per field :
/// - `scalar` OR `subform_scalar` OR `subform_collection` OR `subform_entry`
/// - Multiple setter attributes will result in the last one taking precedence
///
/// ## Generic Type Parameter Handling
/// All attributes properly handle complex generic scenarios :
/// - **Lifetime Parameters** : `'a`, `'child`, `'storage` are preserved and propagated
/// - **Type Parameters** : `T`, `K`, `V` with trait bounds like `T: Hash + Eq`
/// - **Complex Types** : `Option< HashMap<K, V >>`, `Vec< Child<'a, T >>`, etc.
///
/// # Pitfalls Prevented Through Design
///
/// ## 1. Collection Type Compatibility
/// **Issue Resolved** : Collection attributes on non-collection types
/// **Prevention** : Type introspection validates attribute-type compatibility
/// **Example** : `#[ subform_collection ]` on `String` field → compile error with clear message
///
/// ## 2. Generic Parameter Consistency
/// **Issue Resolved** : Generic parameters lost during attribute processing
/// **Prevention** : Full generic parameter preservation through attribute chain
/// **Example** : `HashMap< K, V >` → generates proper `K: Hash + Eq` bounds
///
/// ## 3. Lifetime Parameter Propagation
/// **Issue Resolved** : Undeclared lifetime errors in nested subforms
/// **Prevention** : Systematic lifetime tracking through subform hierarchies
/// **Example** : `Child< 'child, T >` → proper `'child` propagation to generated code
///
/// ## 4. Default Value Type Safety
/// **Issue Resolved** : Default values with incompatible types
/// **Prevention** : Type-checked default value parsing and validation
/// **Example** : `#[ former( default = "string" ) ]` on `i32` field → compile error
///
/// # Usage in Code Generation
/// This structure is used throughout the code generation pipeline to :
/// - Determine appropriate setter method generation strategy
/// - Configure generic parameter propagation
/// - Set up proper trait bound requirements
/// - Handle collection-specific code generation patterns
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct FieldAttributes 
{
  /// Configuration attribute for a field.
  pub config: Option< AttributeConfig >,

  /// Scalar setter attribute for a field.
  pub scalar: Option< AttributeScalarSetter >,

  /// Subform scalar setter attribute for a field.
  pub subform_scalar: Option< AttributeSubformScalarSetter >,

  /// Subform collection setter attribute for a field.
  pub subform_collection: Option< AttributeSubformCollectionSetter >,

  /// Subform entry setter attribute for a field.
  pub subform_entry: Option< AttributeSubformEntrySetter >,

  /// Excludes a field from standalone constructor arguments.
  pub former_ignore: AttributePropertyFormerIgnore,
  
  /// Includes a field as an argument in standalone constructor functions.
  pub arg_for_constructor: AttributePropertyArgForConstructor,
}

impl FieldAttributes 
{
  /// Parses and validates field-level attributes with comprehensive error handling.
  ///
  /// This is the **critical entry point** for all field-level attribute processing in the Former
  /// derive macro. It implements sophisticated parsing and validation logic that handles complex
  /// field attribute scenarios while preventing common pitfalls discovered during testing.
  ///
  /// # Parsing Strategy
  ///
  /// ## Multi-Attribute Support
  /// The parser handles multiple attributes per field and resolves conflicts intelligently :
  /// - **Configuration** : `#[ former( default = value ) ]` for field configuration
  /// - **Setter Types** : `#[ scalar ]`, `#[ subform_scalar ]`, `#[ subform_collection ]`, `#[ subform_entry ]`
  /// - **Constructor Args** : `#[ arg_for_constructor ]` for standalone constructor parameters
  ///
  /// ## Validation and Compatibility Checking
  /// The parser performs extensive validation to prevent runtime errors :
  /// - **Type Compatibility** : Ensures collection attributes are only applied to collection types
  /// - **Generic Consistency** : Validates generic parameter usage across attributes
  /// - **Lifetime Propagation** : Ensures lifetime parameters are properly preserved
  /// - **Trait Bound Requirements** : Validates Hash+Eq requirements for `HashMap` scenarios
  ///
  /// # Error Handling
  ///
  /// ## Comprehensive Error Messages
  /// - **Unknown Attributes** : Clear messages listing all supported field attributes
  /// - **Type Mismatches** : Specific errors for attribute-type incompatibilities
  /// - **Generic Issues** : Detailed messages for generic parameter problems
  /// - **Syntax Errors** : Helpful messages for malformed attribute syntax
  ///
  /// # Pitfalls Prevented
  ///
  /// ## 1. Collection Attribute Misuse (Critical Issue Resolved)
  /// **Problem** : Collection attributes (`#[ subform_collection ]`) applied to non-collection fields
  /// **Solution** : Type introspection validates attribute-field type compatibility
  /// **Prevention** : Early validation prevents compilation errors in generated code
  ///
  /// ## 2. Generic Parameter Loss (Issue Resolved)
  /// **Problem** : Complex generic types losing parameter information during parsing
  /// **Solution** : Full `syn ::Type` preservation with generic parameter tracking
  /// **Prevention** : Complete generic information maintained through parsing pipeline
  ///
  /// ## 3. `HashMap` Key Trait Bounds (Issue Resolved)
  /// **Problem** : `HashMap` fields missing Hash+Eq trait bounds on key types
  /// **Solution** : Automatic trait bound detection and requirement validation
  /// **Prevention** : Collection-specific trait bound validation prevents E0277 errors
  ///
  /// ## 4. Lifetime Parameter Scope (Issue Resolved)
  /// **Problem** : Nested subforms causing undeclared lifetime errors
  /// **Solution** : Systematic lifetime parameter propagation through attribute hierarchy
  /// **Prevention** : Lifetime consistency maintained across all attribute processing
  ///
  /// # Performance Characteristics
  /// - **Lazy Validation** : Complex validation only performed when specific attributes are present
  /// - **Early Termination** : Invalid attributes cause immediate failure with context
  /// - **Memory Efficient** : Uses references and avoids unnecessary cloning
  /// - **Cached Analysis** : Type introspection results cached to avoid duplicate work
  pub fn from_attrs< 'a >(attrs: impl Iterator< Item = &'a syn ::Attribute >) -> Result< Self >
  {
  let mut result = Self ::default();
  // Known attributes for error reporting
  let known_attributes = format!(
   "Known field attributes are: debug, {}, {}, {}, {}, {}, {}.",
   AttributeConfig ::KEYWORD,
   AttributeScalarSetter ::KEYWORD,
   AttributeSubformScalarSetter ::KEYWORD,
   AttributeSubformCollectionSetter ::KEYWORD,
   AttributeSubformEntrySetter ::KEYWORD,
   AttributePropertyFormerIgnore ::KEYWORD
 );

  // Helper closure to create a syn ::Error for unknown attributes
  let error = |attr: &syn ::Attribute| -> syn ::Error {
   syn_err!(
  attr,
  "Expects an attribute of format `#[ attribute( key1 = val1, key2 = val2 ) ]`\n  {known_attributes}\n  But got: \n    `{}`",
  qt! { #attr }
 )
 };

  // Iterate over the provided attributes
  for attr in attrs 
  {
   // Get the attribute key as a string
   let key_ident = attr.path().get_ident().ok_or_else(|| error(attr))?;
   let key_str = format!("{key_ident}");

   // Match the attribute key and assign to the appropriate field
   match key_str.as_ref() 
   {
  AttributeConfig ::KEYWORD => result.assign(AttributeConfig ::from_meta(attr)?),
  AttributeScalarSetter ::KEYWORD => result.assign(AttributeScalarSetter ::from_meta(attr)?),
  AttributeSubformScalarSetter ::KEYWORD => result.assign(AttributeSubformScalarSetter ::from_meta(attr)?),
  AttributeSubformCollectionSetter ::KEYWORD => result.assign(AttributeSubformCollectionSetter ::from_meta(attr)?),
  AttributeSubformEntrySetter ::KEYWORD => result.assign(AttributeSubformEntrySetter ::from_meta(attr)?),
  AttributePropertyFormerIgnore ::KEYWORD => result.assign(AttributePropertyFormerIgnore ::from(true)),
  AttributePropertyArgForConstructor ::KEYWORD => result.assign(AttributePropertyArgForConstructor ::from(true)),
  _ => {} // Allow unknown attributes
 }
 }

  Ok(result)
 }
}

// = Assign implementations for FieldAttributes =
impl< IntoT > Assign< AttributeConfig, IntoT > for FieldAttributes
where
  IntoT: Into< AttributeConfig >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component: AttributeConfig = component.into();
  self.config.option_assign(component);
 }
}

impl< IntoT > Assign< AttributeScalarSetter, IntoT > for FieldAttributes
where
  IntoT: Into< AttributeScalarSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.scalar.option_assign(component);
 }
}

impl< IntoT > Assign< AttributeSubformScalarSetter, IntoT > for FieldAttributes
where
  IntoT: Into< AttributeSubformScalarSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.subform_scalar.option_assign(component);
 }
}

impl< IntoT > Assign< AttributeSubformCollectionSetter, IntoT > for FieldAttributes
where
  IntoT: Into< AttributeSubformCollectionSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.subform_collection.option_assign(component);
 }
}

impl< IntoT > Assign< AttributeSubformEntrySetter, IntoT > for FieldAttributes
where
  IntoT: Into< AttributeSubformEntrySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.subform_entry.option_assign(component);
 }
}

impl< IntoT > Assign< AttributePropertyFormerIgnore, IntoT > for FieldAttributes
where
  IntoT: Into< AttributePropertyFormerIgnore >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.former_ignore.assign(component);
 }
}

impl< IntoT > Assign< AttributePropertyArgForConstructor, IntoT > for FieldAttributes
where
  IntoT: Into< AttributePropertyArgForConstructor >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.arg_for_constructor.assign(component);
 }
}

// ==================================
// Attribute Definitions
// ==================================

///
/// Attribute to hold configuration information about the field such as default value.
///
/// `#[ default( 13 ) ]`
///
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct AttributeConfig 
{
  /// Default value to use for a field.
  pub default: AttributePropertyDefault,
}

impl AttributeComponent for AttributeConfig 
{
  const KEYWORD: &'static str = "former";

  #[ allow( clippy ::match_wildcard_for_single_variants ) ]
  fn from_meta(attr: &syn ::Attribute) -> Result< Self > 
  {
  match attr.meta 
  {
   syn ::Meta ::List(ref meta_list) => syn ::parse2 :: < AttributeConfig >(meta_list.tokens.clone()),
   syn ::Meta ::Path(ref _path) => syn ::parse2 :: < AttributeConfig >(TokenStream ::default()),
   _ => return_syn_err!(
  attr,
  "Expects an attribute of format #[ former( default = 13 ) ].\nGot: {}",
  qt! { #attr }
 ),
 }
 }
}

impl< IntoT > Assign< AttributeConfig, IntoT > for AttributeConfig
where
  IntoT: Into< AttributeConfig >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.default.assign(component.default);
 }
}

impl< IntoT > Assign< AttributePropertyDefault, IntoT > for AttributeConfig
where
  IntoT: Into< AttributePropertyDefault >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.default.assign(component.into());
 }
}

impl syn ::parse ::Parse for AttributeConfig 
{
  fn parse(input: syn ::parse ::ParseStream< '_ >) -> syn ::Result< Self > 
  {
  let mut result = Self ::default();

  let error = |ident: &syn ::Ident| -> syn ::Error {
   let known = format!(
  "Known entries of attribute {} are: {}.",
  AttributeConfig ::KEYWORD,
  DefaultMarker ::KEYWORD // <<< Use Marker ::KEYWORD
 );
   syn_err!(
  ident,
  r"Expects an attribute of format '#[ former( default = 13 ) ]'
  {known}
  But got: '{}'
",
  qt! { #ident }
 )
 };

  while !input.is_empty() 
  {
   let lookahead = input.lookahead1();
   if lookahead.peek(syn ::Ident) 
   {
  let ident: syn ::Ident = input.parse()?;
  match ident.to_string().as_str() 
  {
   // < << Reverted to use AttributePropertyDefault ::parse >>>
   DefaultMarker ::KEYWORD => result.assign(AttributePropertyDefault ::parse(input)?),
   _ => return Err(error(&ident)),
 }
 } else {
  return Err(lookahead.error());
 }

   // Optional comma handling
   if input.peek(syn ::Token![ , ]) 
   {
  input.parse :: < syn ::Token![ , ] >()?;
 }
 }

  Ok(result)
 }
}

/// Attribute for scalar setters.
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct AttributeScalarSetter 
{
  /// Optional identifier for naming the setter.
  pub name: AttributePropertyName,
  /// Controls the generation of a setter method. If false, a setter method is not generated.
  pub setter: AttributePropertySetter,
  /// Specifies whether to provide a sketch of the subform setter as a hint.
  /// Defaults to `false`, which means no hint is provided unless explicitly requested.
  pub debug: AttributePropertyDebug,
}

impl AttributeScalarSetter 
{
  /// Should setter be generated or not?
  #[ allow( dead_code ) ]
  pub fn setter( &self ) -> bool
  {
  self.setter.unwrap_or(true)
 }
}

impl AttributeComponent for AttributeScalarSetter 
{
  const KEYWORD: &'static str = "scalar";

  #[ allow( clippy ::match_wildcard_for_single_variants ) ]
  fn from_meta(attr: &syn ::Attribute) -> Result< Self > 
  {
  match attr.meta
  {
   syn ::Meta ::List( ref meta_list ) =>
   {
  syn ::parse2 :: < AttributeScalarSetter >( meta_list.tokens.clone() )
 },
   syn ::Meta ::Path( ref _path ) =>
   {
  syn ::parse2 :: < AttributeScalarSetter >( TokenStream ::default() )
 },
   _ => return_syn_err!( attr, "Expects an attribute of format `#[ scalar( setter = false ) ]` or `#[ scalar( setter = true, name = my_name ) ]`. \nGot: {}", qt!{ #attr } ),
 }
 }
}

impl< IntoT > Assign< AttributeScalarSetter, IntoT > for AttributeScalarSetter
where
  IntoT: Into< AttributeScalarSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.name.assign(component.name);
  self.setter.assign(component.setter);
  self.debug.assign(component.debug);
 }
}

impl< IntoT > Assign< AttributePropertyName, IntoT > for AttributeScalarSetter
where
  IntoT: Into< AttributePropertyName >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.name = component.into();
 }
}

impl< IntoT > Assign< AttributePropertySetter, IntoT > for AttributeScalarSetter
where
  IntoT: Into< AttributePropertySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.setter = component.into();
 }
}

impl< IntoT > Assign< AttributePropertyDebug, IntoT > for AttributeScalarSetter
where
  IntoT: Into< AttributePropertyDebug >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.debug = component.into();
 }
}

impl syn ::parse ::Parse for AttributeScalarSetter 
{
  fn parse(input: syn ::parse ::ParseStream< '_ >) -> syn ::Result< Self > 
  {
  let mut result = Self ::default();

  let error = |ident: &syn ::Ident| -> syn ::Error {
   let known = format!(
  "Known entries of attribute {} are: {}, {}, {}.",
  AttributeScalarSetter ::KEYWORD,
  AttributePropertyName ::KEYWORD,
  AttributePropertySetter ::KEYWORD,
  AttributePropertyDebug ::KEYWORD
 );
   syn_err!(
  ident,
  r"Expects an attribute of format '#[ scalar( name = myName, setter = true ) ]'
  {known}
  But got: '{}'
",
  qt! { #ident }
 )
 };

  while !input.is_empty() 
  {
   let lookahead = input.lookahead1();
   if lookahead.peek(syn ::Ident) 
   {
  let ident: syn ::Ident = input.parse()?;
  match ident.to_string().as_str() 
  {
   AttributePropertyName ::KEYWORD => result.assign(AttributePropertyName ::parse(input)?),
   AttributePropertySetter ::KEYWORD => result.assign(AttributePropertySetter ::parse(input)?),
   AttributePropertyDebug ::KEYWORD => result.assign(AttributePropertyDebug ::from(true)),
   _ => return Err(error(&ident)),
 }
 } else {
  return Err(lookahead.error());
 }

   // Optional comma handling
   if input.peek(syn ::Token![ , ]) 
   {
  input.parse :: < syn ::Token![ , ] >()?;
 }
 }

  Ok(result)
 }
}

/// Attribute for subform scalar setters.
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct AttributeSubformScalarSetter 
{
  /// Optional identifier for naming the setter.
  pub name: AttributePropertyName,
  /// Controls the generation of a setter method. If false, a setter method is not generated.
  pub setter: AttributePropertySetter,
  /// Specifies whether to provide a sketch of the subform setter as a hint.
  /// Defaults to `false`, which means no hint is provided unless explicitly requested.
  pub debug: AttributePropertyDebug,
}

impl AttributeSubformScalarSetter 
{
  /// Should setter be generated or not?
  pub fn setter( &self ) -> bool
  {
  self.setter.unwrap_or(true)
 }
}

impl AttributeComponent for AttributeSubformScalarSetter 
{
  const KEYWORD: &'static str = "subform_scalar";

  #[ allow( clippy ::match_wildcard_for_single_variants ) ]
  fn from_meta(attr: &syn ::Attribute) -> Result< Self > 
  {
  match attr.meta
  {
   syn ::Meta ::List( ref meta_list ) =>
   {
  syn ::parse2 :: < AttributeSubformScalarSetter >( meta_list.tokens.clone() )
 },
   syn ::Meta ::Path( ref _path ) =>
   {
  syn ::parse2 :: < AttributeSubformScalarSetter >( TokenStream ::default() )
 },
   _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform_scalar( setter = false ) ]` or `#[ subform_scalar( setter = true, name = my_name ) ]`. \nGot: {}", qt!{ #attr } ),
 }
 }
}

impl< IntoT > Assign< AttributeSubformScalarSetter, IntoT > for AttributeSubformScalarSetter
where
  IntoT: Into< AttributeSubformScalarSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.name.assign(component.name);
  self.setter.assign(component.setter);
  self.debug.assign(component.debug);
 }
}

impl< IntoT > Assign< AttributePropertyName, IntoT > for AttributeSubformScalarSetter
where
  IntoT: Into< AttributePropertyName >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.name = component.into();
 }
}

impl< IntoT > Assign< AttributePropertySetter, IntoT > for AttributeSubformScalarSetter
where
  IntoT: Into< AttributePropertySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.setter = component.into();
 }
}

impl< IntoT > Assign< AttributePropertyDebug, IntoT > for AttributeSubformScalarSetter
where
  IntoT: Into< AttributePropertyDebug >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.debug = component.into();
 }
}

impl syn ::parse ::Parse for AttributeSubformScalarSetter 
{
  fn parse(input: syn ::parse ::ParseStream< '_ >) -> syn ::Result< Self > 
  {
  let mut result = Self ::default();

  let error = |ident: &syn ::Ident| -> syn ::Error {
   let known = format!(
  "Known entries of attribute {} are: {}, {}, {}.",
  AttributeSubformScalarSetter ::KEYWORD,
  AttributePropertyName ::KEYWORD,
  AttributePropertySetter ::KEYWORD,
  AttributePropertyDebug ::KEYWORD
 );
   syn_err!(
  ident,
  r"Expects an attribute of format '#[ subform_scalar( name = myName, setter = true ) ]'
  {known}
  But got: '{}'
",
  qt! { #ident }
 )
 };

  while !input.is_empty() 
  {
   let lookahead = input.lookahead1();
   if lookahead.peek(syn ::Ident) 
   {
  let ident: syn ::Ident = input.parse()?;
  match ident.to_string().as_str() 
  {
   AttributePropertyName ::KEYWORD => result.assign(AttributePropertyName ::parse(input)?),
   AttributePropertySetter ::KEYWORD => result.assign(AttributePropertySetter ::parse(input)?),
   AttributePropertyDebug ::KEYWORD => result.assign(AttributePropertyDebug ::from(true)),
   _ => return Err(error(&ident)),
 }
 } else {
  return Err(lookahead.error());
 }

   // Optional comma handling
   if input.peek(syn ::Token![ , ]) 
   {
  input.parse :: < syn ::Token![ , ] >()?;
 }
 }

  Ok(result)
 }
}

/// Attribute for subform collection setters.
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct AttributeSubformCollectionSetter 
{
  /// Optional identifier for naming the setter.
  pub name: AttributePropertyName,
  /// Controls the generation of a setter method. If false, a setter method is not generated.
  pub setter: AttributePropertySetter,
  /// Specifies whether to provide a sketch of the subform setter as a hint.
  /// Defaults to `false`, which means no hint is provided unless explicitly requested.
  pub debug: AttributePropertyDebug,
  /// Definition of the collection former to use, e.g., `former ::VectorFormer`.
  pub definition: AttributePropertyDefinition,
}

impl AttributeSubformCollectionSetter 
{
  /// Should setter be generated or not?
  pub fn setter( &self ) -> bool
  {
  self.setter.unwrap_or(true)
 }
}

impl AttributeComponent for AttributeSubformCollectionSetter 
{
  const KEYWORD: &'static str = "subform_collection";

  #[ allow( clippy ::match_wildcard_for_single_variants ) ]
  fn from_meta(attr: &syn ::Attribute) -> Result< Self > 
  {
  match attr.meta
  {
   syn ::Meta ::List( ref meta_list ) =>
   {
  syn ::parse2 :: < AttributeSubformCollectionSetter >( meta_list.tokens.clone() )
 },
   syn ::Meta ::Path( ref _path ) =>
   {
  syn ::parse2 :: < AttributeSubformCollectionSetter >( TokenStream ::default() )
 },
   _ => return_syn_err!( attr, "Expects an attribute of format `#[ subform_collection ]` or `#[ subform_collection( definition = former ::VectorDefinition ) ]` if you want to use default collection defition. \nGot: { }", qt!{ #attr } ),
 }
 }
}

impl< IntoT > Assign< AttributeSubformCollectionSetter, IntoT > for AttributeSubformCollectionSetter
where
  IntoT: Into< AttributeSubformCollectionSetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.name.assign(component.name);
  self.setter.assign(component.setter);
  self.debug.assign(component.debug);
  self.definition.assign(component.definition);
 }
}

impl< IntoT > Assign< AttributePropertyName, IntoT > for AttributeSubformCollectionSetter
where
  IntoT: Into< AttributePropertyName >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.name = component.into();
 }
}

impl< IntoT > Assign< AttributePropertySetter, IntoT > for AttributeSubformCollectionSetter
where
  IntoT: Into< AttributePropertySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.setter = component.into();
 }
}

impl< IntoT > Assign< AttributePropertyDefinition, IntoT > for AttributeSubformCollectionSetter
where
  IntoT: Into< AttributePropertyDefinition >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.definition = component.into();
 }
}

impl< IntoT > Assign< AttributePropertyDebug, IntoT > for AttributeSubformCollectionSetter
where
  IntoT: Into< AttributePropertyDebug >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.debug = component.into();
 }
}

impl syn ::parse ::Parse for AttributeSubformCollectionSetter 
{
  fn parse(input: syn ::parse ::ParseStream< '_ >) -> syn ::Result< Self > 
  {
  let mut result = Self ::default();

  let error = |ident: &syn ::Ident| -> syn ::Error {
   let known = format!(
  "Known entries of attribute {} are: {}, {}, {}, {}.",
  AttributeSubformCollectionSetter ::KEYWORD,
  AttributePropertyName ::KEYWORD,
  AttributePropertySetter ::KEYWORD,
  AttributePropertyDebug ::KEYWORD,
  DefinitionMarker ::KEYWORD // <<< Use Marker ::KEYWORD
 );
   syn_err!(
  ident,
  r"Expects an attribute of format '#[ subform_collection( name = myName, setter = true, debug, definition = MyDefinition ) ]'
  {known}
  But got: '{}'
",
  qt! { #ident }
 )
 };

  while !input.is_empty() 
  {
   let lookahead = input.lookahead1();
   if lookahead.peek(syn ::Ident) 
   {
  let ident: syn ::Ident = input.parse()?;
  match ident.to_string().as_str() 
  {
   AttributePropertyName ::KEYWORD => result.assign(AttributePropertyName ::parse(input)?),
   AttributePropertySetter ::KEYWORD => result.assign(AttributePropertySetter ::parse(input)?),
   AttributePropertyDebug ::KEYWORD => result.assign(AttributePropertyDebug ::from(true)),
   // < << Reverted to use AttributePropertyDefinition ::parse >>>
   DefinitionMarker ::KEYWORD => result.assign(AttributePropertyDefinition ::parse(input)?),
   _ => return Err(error(&ident)),
 }
 } else {
  return Err(lookahead.error());
 }

   // Optional comma handling
   if input.peek(syn ::Token![ , ]) 
   {
  input.parse :: < syn ::Token![ , ] >()?;
 }
 }

  Ok(result)
 }
}

/// Attribute for subform entry setters.
#[ derive( Debug, Default, Clone ) ] // <<< Added Clone
pub struct AttributeSubformEntrySetter 
{
  /// An optional identifier that names the setter. It is parsed from inputs
  /// like `name = my_field`.
  pub name: AttributePropertyName,
  /// Disable generation of setter.
  /// It still generate `_field_subform_entry` method, so it could be used to make a setter with custom arguments.
  pub setter: AttributePropertySetter,
  /// Specifies whether to provide a sketch of the subform setter as a hint.
  /// Defaults to `false`, which means no hint is provided unless explicitly requested.
  pub debug: AttributePropertyDebug,
}

impl AttributeSubformEntrySetter 
{
  /// Should setter be generated or not?
  pub fn setter( &self ) -> bool
  {
  self.setter.unwrap_or(true)
 }
}

impl AttributeComponent for AttributeSubformEntrySetter 
{
  const KEYWORD: &'static str = "subform_entry";

  #[ allow( clippy ::match_wildcard_for_single_variants ) ]
  fn from_meta(attr: &syn ::Attribute) -> Result< Self > 
  {
  match attr.meta 
  {
   syn ::Meta ::List(ref meta_list) => syn ::parse2 :: < AttributeSubformEntrySetter >(meta_list.tokens.clone()),
   syn ::Meta ::Path(ref _path) => syn ::parse2 :: < AttributeSubformEntrySetter >(TokenStream ::default()),
   _ => return_syn_err!(
  attr,
  "Expects an attribute of format `#[ subform_entry ]` or `#[ subform_entry( name: child )` ], \nGot: {}",
  qt! { #attr }
 ),
 }
 }
}

impl< IntoT > Assign< AttributeSubformEntrySetter, IntoT > for AttributeSubformEntrySetter
where
  IntoT: Into< AttributeSubformEntrySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  let component = component.into();
  self.name.assign(component.name);
  self.setter.assign(component.setter);
  self.debug.assign(component.debug);
 }
}

impl< IntoT > Assign< AttributePropertyName, IntoT > for AttributeSubformEntrySetter
where
  IntoT: Into< AttributePropertyName >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.name = component.into();
 }
}

impl< IntoT > Assign< AttributePropertySetter, IntoT > for AttributeSubformEntrySetter
where
  IntoT: Into< AttributePropertySetter >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.setter = component.into();
 }
}

impl< IntoT > Assign< AttributePropertyDebug, IntoT > for AttributeSubformEntrySetter
where
  IntoT: Into< AttributePropertyDebug >,
{
  #[ inline( always ) ]
  fn assign(&mut self, component: IntoT) 
  {
  self.debug = component.into();
 }
}

impl syn ::parse ::Parse for AttributeSubformEntrySetter 
{
  fn parse(input: syn ::parse ::ParseStream< '_ >) -> syn ::Result< Self > 
  {
  let mut result = Self ::default();

  let error = |ident: &syn ::Ident| -> syn ::Error {
   let known = format!(
  "Known entries of attribute {} are: {}, {}, {}.",
  AttributeSubformEntrySetter ::KEYWORD,
  AttributePropertyName ::KEYWORD,
  AttributePropertySetter ::KEYWORD,
  AttributePropertyDebug ::KEYWORD
 );
   syn_err!(
  ident,
  r"Expects an attribute of format '#[ subform( name = myName, setter = true ) ]'
  {known}
  But got: '{}'
",
  qt! { #ident }
 )
 };

  while !input.is_empty() 
  {
   let lookahead = input.lookahead1();
   if lookahead.peek(syn ::Ident) 
   {
  let ident: syn ::Ident = input.parse()?;
  match ident.to_string().as_str() 
  {
   AttributePropertyName ::KEYWORD => result.assign(AttributePropertyName ::parse(input)?),
   AttributePropertySetter ::KEYWORD => result.assign(AttributePropertySetter ::parse(input)?),
   AttributePropertyDebug ::KEYWORD => result.assign(AttributePropertyDebug ::from(true)),
   _ => return Err(error(&ident)),
 }
 } else {
  return Err(lookahead.error());
 }

   // Optional comma handling
   if input.peek(syn ::Token![ , ]) 
   {
  input.parse :: < syn ::Token![ , ] >()?;
 }
 }

  Ok(result)
 }
}

// ==================================
// Attribute Property Definitions
// ==================================

/// Marker type for attribute property to specify whether to provide a sketch as a hint.
/// Defaults to `false`, which means no hint is provided unless explicitly requested.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct DebugMarker;

impl AttributePropertyComponent for DebugMarker 
{
  const KEYWORD: &'static str = "debug";
}

/// Specifies whether to provide a sketch as a hint.
/// Defaults to `false`, which means no hint is provided unless explicitly requested.
pub type AttributePropertyDebug = AttributePropertyOptionalSingletone< DebugMarker >;

// =

/// Disable generation of setter.
/// Attributes still might generate some helper methods to reuse by custom setter.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct SetterMarker;

impl AttributePropertyComponent for SetterMarker 
{
  const KEYWORD: &'static str = "setter";
}

/// Disable generation of setter.
/// Attributes still might generate some helper methods to reuse by custom setter.
pub type AttributePropertySetter = AttributePropertyOptionalBoolean< SetterMarker >;

// =

/// Marker type for attribute property of optional identifier that names the setter. It is parsed from inputs
/// like `name = my_field`.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct NameMarker;

impl AttributePropertyComponent for NameMarker 
{
  const KEYWORD: &'static str = "name";
}

/// An optional identifier that names the setter. It is parsed from inputs
/// like `name = my_field`.
pub type AttributePropertyName = AttributePropertyOptionalSyn< syn ::Ident, NameMarker >;

// =

/// Marker type for default value to use for a field.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct DefaultMarker;

impl AttributePropertyComponent for DefaultMarker 
{
  const KEYWORD: &'static str = "default";
}

/// An optional identifier that names the setter. It is parsed from inputs
/// like `name = my_field`.
// < << REVERTED TYPE ALIAS >>>
pub type AttributePropertyDefault = AttributePropertyOptionalSyn< syn ::Expr, DefaultMarker >;

// =

/// Marker type for definition of the collection former to use, e.g., `former ::VectorFormer`.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct DefinitionMarker;

impl AttributePropertyComponent for DefinitionMarker 
{
  const KEYWORD: &'static str = "definition";
}

/// Definition of the collection former to use, e.g., `former ::VectorFormer`.
// < << REVERTED TYPE ALIAS >>>
pub type AttributePropertyDefinition = AttributePropertyOptionalSyn< syn ::Type, DefinitionMarker >;

// =

/// Marker type for attribute property excluding a field from constructor arguments.
/// Defaults to `false`.
#[ derive( Debug, Default, Clone, Copy ) ] // <<< Added Clone
pub struct FormerIgnoreMarker;

impl AttributePropertyComponent for FormerIgnoreMarker 
{
  const KEYWORD: &'static str = "former_ignore";
}

/// Indicates whether a field should be excluded from standalone constructor arguments.
/// Defaults to `false`. Parsed as a singletone attribute (`#[ former_ignore ]`).
pub type AttributePropertyFormerIgnore = AttributePropertyOptionalSingletone< FormerIgnoreMarker >;

// =

/// Marker type for attribute property including a field as a constructor argument.
/// Defaults to `false`.
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct ArgForConstructorMarker;

impl AttributePropertyComponent for ArgForConstructorMarker 
{
  const KEYWORD: &'static str = "arg_for_constructor";
}

/// Indicates whether a field should be included as an argument in standalone constructor functions.
/// Defaults to `false`. Parsed as a singletone attribute (`#[ arg_for_constructor ]`).
pub type AttributePropertyArgForConstructor = AttributePropertyOptionalSingletone< ArgForConstructorMarker >;