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
//! Contains utility macros for the `field` module.
//!
//! These macros help reduce boilerplate code when implementing common traits
//! for the various field enums.
/// Implements `std::fmt::Display` for a field enum with complex (nested) variants.
///
/// This macro handles field enums that contain both simple variants (e.g., `Title`)
/// and complex variants that hold a `Vec` of sub-fields (e.g., `User(Vec<UserField>)`).
///
/// - For simple variants, it relies on `strum`'s `AsRefStr` trait to produce the `camelCase` string.
/// - For complex variants, it formats them as `fieldName(subField1,subField2,...)`.
///
/// # Arguments
/// * `$enum_name:ident` - The name of the enum to implement `Display` for.
/// * `$( $variant:ident => $name:literal ),*` - A comma-separated list of the complex variants.
/// Each entry specifies the `VariantName` and the exact string literal to use for its name.
///
/// # Example
/// ```
///
/// // An enum with simple and complex variants
/// use wp_mini::impl_field_display;
///
/// #[derive(strum_macros::AsRefStr)]
/// #[strum(serialize_all = "camelCase")]
/// enum StoryField {
/// Title,
/// VoteCount,
/// // A complex variant with sub-fields
/// User(Vec<UserField>),
/// }
///
/// #[derive(strum_macros::AsRefStr)]
/// #[strum(serialize_all = "camelCase")]
/// enum UserField {
/// Username,
/// Avatar,
/// }
///
/// // Generate the Display implementation using the macro
/// impl_field_display!(StoryField, User => "user");
///
/// // --- Verification ---
/// // Simple field
/// let simple_field = StoryField::VoteCount;
/// assert_eq!(simple_field.to_string(), "voteCount");
///
/// // Complex field
/// let complex_field = StoryField::User(vec![UserField::Username, UserField::Avatar]);
/// assert_eq!(complex_field.to_string(), "user(username,avatar)");
/// ```