Skip to content

Commit 3607b74

Browse files
committed
wip
1 parent 457e66c commit 3607b74

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

module/core/former_meta/src/derive_former/former_enum.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,34 @@ use macro_tools::
1414
#[ cfg( feature = "derive_former" ) ]
1515
use convert_case::{ Case, Casing }; // Space before ;
1616

17+
1718
// ==================================
1819
// Enum Variant Handling Rules (Consistent Logic)
1920
// ==================================
20-
// ... (Rules documentation remains the same) ...
21+
//
22+
// This macro implements the `Former` derive for enums based on the following consistent rules:
23+
//
24+
// 1. **`#[scalar]` Attribute:**
25+
// * **Unit Variant:** Generates `Enum::variant() -> Enum`.
26+
// * **Zero-Field Variant Generates `Enum::variant() -> Enum`.
27+
// * **Single-Field Variant (Tuple or Struct):** Generates `Enum::variant(InnerType) -> Enum`.
28+
// * **Multi-Field Variant (Tuple or Struct):** Generates `Enum::variant(Field1Type, Field2Type, ...) -> Enum`.
29+
// * **Error Cases:** Cannot be combined with `#[subform_scalar]`.
30+
//
31+
// 2. **`#[subform_scalar]` Attribute:**
32+
// * **Unit Variant:** Error.
33+
// * **Zero-Field Variant (Tuple or Struct):** Error.
34+
// * **Single-Field Variant (Tuple or Struct):** Generates `Enum::variant() -> InnerFormer<...>` (where `InnerFormer` is the former for the field's type). Requires the field type to be a path type deriving `Former`.
35+
// * **Multi-Field Variant (Tuple or Struct):** Generates `Enum::variant() -> InnerFormer<...>` (where `InnerFormer` is the former for the field's type). Requires the field type to be a path type deriving `Former`.
36+
//
37+
// 3. **Default Behavior (No Attribute):**
38+
// * **Unit Variant:** Generates `Enum::variant() -> Enum`.
39+
// * **Zero-Field Variant Generates `Enum::variant() -> Enum`.
40+
// * **Single-Field Variant (Tuple or Struct):** Generates `Enum::variant() -> InnerFormer<...>` (where `InnerFormer` is the former for the field's type). Requires the field type to be a path type deriving `Former`.
41+
// * **Multi-Field Variant (Tuple or Struct):** Generates `Enum::variant() -> InnerFormer<...>` (where `InnerFormer` is the former for the field's type). Requires the field type to be a path type deriving `Former`.
42+
//
43+
// Body attribute `standalone_constructors` creates stand-alone, top-level constructors for struct/enum. for struct it's always single function, for enum it's as many functions as enum has vartianys.
44+
//
2145
// ==================================
2246

2347
/// Temporary storage for field information needed during generation.

0 commit comments

Comments
 (0)