lombok_macros/
lib.rs

1//! lombok-macros
2//!
3//! A Rust procedural macro collection providing Lombok-like functionality.
4//! Automatically generates getters/setters with field-level visibility control,
5//! custom Debug implementations with field skipping, and Display trait implementations.
6//! Supports structs, enums, generics and lifetimes.
7
8pub(crate) mod config;
9pub(crate) mod func;
10pub(crate) mod generate;
11pub(crate) mod parse;
12pub(crate) mod visibility;
13
14pub(crate) use config::*;
15pub(crate) use func::*;
16pub(crate) use generate::*;
17pub(crate) use parse::*;
18pub(crate) use visibility::*;
19
20pub(crate) use proc_macro::TokenStream;
21pub(crate) use proc_macro2::{
22    Delimiter, TokenStream as TokenStream2, TokenTree as TokenTree2, token_stream::IntoIter,
23};
24pub(crate) use quote::{ToTokens, format_ident, quote};
25pub(crate) use std::{
26    collections::{HashMap, HashSet},
27    fmt::{Display, Formatter},
28    iter::Peekable,
29    str::FromStr,
30};
31pub(crate) use syn::{
32    Data, DeriveInput, Field, Fields, GenericArgument,
33    GenericParam::{self},
34    Generics, Ident, Index, Lifetime, PathArguments,
35    Type::{self},
36    TypeParam, Variant, WhereClause, parse_macro_input,
37};
38
39/// A procedural macro that automatically generates getter methods for struct and enum fields.
40///
41/// This macro derives getter methods with configurable visibility and return type behavior.
42/// The generated getters can return either references to field values or cloned copies,
43/// with support for Option and Result types.
44///
45/// # Supported Attributes
46/// - `#[get(pub)]` - Generates a public getter with reference return type
47/// - `#[get(pub, reference)]` - Generates a public getter that returns a reference (`&T`)
48/// - `#[get(pub, clone)]` - Generates a public getter that returns a cloned value (`T`)
49/// - `#[get(pub, copy)]` - Generates a public getter that returns a copy of the field value (`self.field`) for Copy types
50/// - `#[get(pub, deref)]` - Generates a public getter that returns a dereferenced value (`*field`) with enhanced match control for Option/Result types
51/// - `#[get(pub(crate))]` - Generates a crate-visible getter
52/// - `#[get(private)]` - Generates a private getter
53///
54/// # Return Type Behavior
55/// - `reference` - Returns `&T` - a reference to the field value
56/// - `clone` - Returns `T` - a cloned copy of the field value  
57/// - `copy` - Returns `T` - a copy of the field value (`self.field`) for types implementing Copy trait
58/// - `deref` - Returns dereferenced values with enhanced match control:
59///   - `Option<T>` → `T` with detailed None panic messages
60///   - `Result<T, E>` → `T` with detailed Err panic messages
61///   - `Box<T>` → `T` by dereferencing the box
62///   - `Rc<T>` → `T` by cloning the inner value
63///   - `Arc<T>` → `T` by cloning the inner value
64///   - Other types → `T` by dereferencing
65/// - Default behavior: Returns `&T` for non-Option/Result types, `T` for Option/Result types
66///
67/// # Default Behavior Details
68/// - **Non-Option/Result types**: Returns `&T` (reference to field)
69/// - **Option/Result types**: Returns `T` (cloned value) to avoid exposing internal references
70/// - This ensures safe access patterns while maintaining performance for common use cases
71///
72/// # Examples
73///
74/// ## Basic Usage
75///
76/// ```rust
77/// use lombok_macros::*;
78///
79/// #[derive(Getter, Clone)]
80/// struct BasicStruct {
81///     #[get(pub)]
82///     name: String,
83///     #[get(pub, type(reference))]
84///     description: String,
85///     #[get(pub, type(clone))]
86///     data: Vec<i32>,
87///     #[get(pub, type(copy))]
88///     count: i32,
89/// }
90/// let basic = BasicStruct {
91///     name: "test".to_string(),
92///     description: "description".to_string(),
93///     data: vec![1, 2, 3],
94///     count: 42,
95/// };
96/// let name_ref: &String = basic.get_name();
97/// let description_ref: &String = basic.get_description();
98/// let data_clone: Vec<i32> = basic.get_data();
99/// let count_copy: i32 = basic.get_count();
100/// assert_eq!(*name_ref, "test");
101/// assert_eq!(*description_ref, "description");
102/// assert_eq!(data_clone, vec![1, 2, 3]);
103/// assert_eq!(count_copy, 42);
104/// ```
105///
106/// ## Option and Result Types
107///
108/// ```rust
109/// use lombok_macros::*;
110///
111/// #[derive(Getter, Clone)]
112/// struct OptionalStruct {
113///     #[get(pub)]
114///     optional: Option<String>,
115///     #[get(pub, type(reference))]
116///     optional_ref: Option<String>,
117///     #[get(pub)]
118///     result: Result<String, String>,
119/// }
120/// let opt_struct = OptionalStruct {
121///     optional: Some("value".to_string()),
122///     optional_ref: Some("ref_value".to_string()),
123///     result: Ok("success".to_string()),
124/// };
125/// let optional_value: String = opt_struct.get_optional();
126/// let optional_reference: &Option<String> = opt_struct.get_optional_ref();
127/// let result_value: String = opt_struct.get_result();
128/// assert_eq!(optional_value, "value");
129/// assert_eq!(*optional_reference, Some("ref_value".to_string()));
130/// assert_eq!(result_value, "success");
131/// ```
132///
133/// ## Tuple Structs
134///
135/// ```rust
136/// use lombok_macros::*;
137///
138/// #[derive(Getter, Clone)]
139/// struct TupleStruct(
140///     #[get(pub)] String,
141///     #[get(pub, type(clone))] Vec<i32>,
142/// );
143/// let tuple = TupleStruct("hello".to_string(), vec![1, 2, 3]);
144/// let field0: &String = tuple.get_0();
145/// let field1: Vec<i32> = tuple.get_1();
146/// assert_eq!(*field0, "hello");
147/// assert_eq!(field1, vec![1, 2, 3]);
148/// ```
149///
150/// ## Copy Return Type
151///
152/// ```rust
153/// use lombok_macros::*;
154///
155/// #[derive(Getter, Clone)]
156/// struct CopyStruct {
157///     #[get(pub, type(copy))]
158///     value: i32,
159///     #[get(pub, type(copy))]
160///     flag: bool,
161///     #[get(pub, type(copy))]
162///     count: u64,
163/// }
164/// let copy_struct = CopyStruct {
165///     value: 42,
166///     flag: true,
167///     count: 1000,
168/// };
169/// let copied_value: i32 = copy_struct.get_value();
170/// let copied_flag: bool = copy_struct.get_flag();
171/// let copied_count: u64 = copy_struct.get_count();
172/// assert_eq!(copied_value, 42);
173/// assert_eq!(copied_flag, true);
174/// assert_eq!(copied_count, 1000);
175/// ```
176///
177/// ## Deref Return Type with Enhanced Match Control
178///
179/// ```rust
180/// use lombok_macros::*;
181///
182/// #[derive(Getter, Clone)]
183/// struct DerefStruct {
184///     #[get(pub, type(deref))]
185///     optional: Option<bool>,
186///     #[get(pub, type(deref))]
187///     result: Result<String, &'static str>,
188///     #[get(pub, type(deref))]
189///     boxed_value: Box<i32>,
190///     #[get(pub, type(deref))]
191///     rc_value: std::rc::Rc<String>,
192///     #[get(pub, type(deref))]
193///     arc_value: std::sync::Arc<Vec<u8>>,
194/// }
195/// let deref_struct = DerefStruct {
196///     optional: Some(true),
197///     result: Ok("success".to_string()),
198///     boxed_value: Box::new(100),
199///     rc_value: std::rc::Rc::new("test".to_string()),
200///     arc_value: std::sync::Arc::new(vec![1, 2, 3]),
201/// };
202/// let optional_value: bool = deref_struct.get_optional();
203/// let result_value: String = deref_struct.get_result();
204/// let boxed_value: i32 = deref_struct.get_boxed_value();
205/// let rc_value: String = deref_struct.get_rc_value();
206/// let arc_value: Vec<u8> = deref_struct.get_arc_value();
207/// assert_eq!(optional_value, true);
208/// assert_eq!(result_value, "success");
209/// assert_eq!(boxed_value, 100);
210/// assert_eq!(rc_value, "test");
211/// assert_eq!(arc_value, vec![1, 2, 3]);
212/// ```
213///
214/// ## Generics and Lifetimes
215///
216/// ```rust
217/// use lombok_macros::*;
218///
219/// #[derive(Getter, Clone)]
220/// struct GenericStruct<'a, T: Clone> {
221///     #[get(pub)]
222///     value: &'a T,
223///     #[get(pub, type(clone))]
224///     owned: T,
225/// }
226/// let data = 42;
227/// let generic = GenericStruct {
228///     value: &data,
229///     owned: 42,
230/// };
231/// let value_ref: &i32 = generic.get_value();
232/// let owned_clone: i32 = generic.get_owned();
233/// assert_eq!(*value_ref, 42);
234/// assert_eq!(owned_clone, 42);
235/// ```
236#[proc_macro_derive(Getter, attributes(get))]
237pub fn getter(input: TokenStream) -> TokenStream {
238    inner_lombok_data(input, true, false, false)
239}
240
241/// A procedural macro that automatically generates mutable getter methods for struct and enum fields.
242///
243/// This macro derives mutable getter methods that provide mutable references to field values,
244/// allowing modification of the struct's fields while maintaining proper borrowing semantics.
245///
246/// # Supported Attributes
247/// - `#[get_mut(pub)]` - Generates a public mutable getter
248/// - `#[get_mut(pub(crate))]` - Generates a crate-visible mutable getter
249/// - `#[get_mut(pub(super))]` - Generates a mutable getter visible to parent module
250/// - `#[get_mut(private)]` - Generates a private mutable getter
251///
252/// # Example
253///
254/// ```rust
255/// use lombok_macros::*;
256///
257/// #[derive(GetterMut, Clone)]
258/// struct StructWithLifetimes<'a, 'b, T: Clone> {
259///     #[get_mut(pub(crate))]
260///     list: Vec<String>,
261///     #[get_mut(pub(crate))]
262///     optional_lifetime_a: Option<&'a T>,
263///     optional_lifetime_b: Option<&'b str>,
264/// }
265/// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
266/// let mut struct_with_lifetimes: StructWithLifetimes<usize> = StructWithLifetimes {
267///     list: list.clone(),
268///     optional_lifetime_a: None,
269///     optional_lifetime_b: None,
270/// };
271/// let mut list_reference: &mut Vec<String> = struct_with_lifetimes.get_mut_list();
272/// list_reference.push("new_item".to_string());
273/// assert_eq!(*list_reference, vec!["hello".to_string(), "world".to_string(), "new_item".to_string()]);
274/// ```
275#[proc_macro_derive(GetterMut, attributes(get_mut))]
276pub fn getter_mut(input: TokenStream) -> TokenStream {
277    inner_lombok_data(input, false, true, false)
278}
279
280/// A procedural macro that automatically generates setter methods for struct and enum fields.
281///
282/// This macro derives setter methods that allow modification of struct fields with
283/// configurable visibility and parameter type conversion options.
284///
285/// # Supported Attributes
286/// - `#[set(pub)]` - Generates a public setter
287/// - `#[set(pub(crate))]` - Generates a crate-visible setter
288/// - `#[set(pub(super))]` - Generates a setter visible to parent module
289/// - `#[set(private)]` - Generates a private setter
290/// - `#[set(pub, type(AsRef<str>))]` - Generates a setter with custom parameter type conversion
291/// - `#[set(pub, Into)]` - Generates a setter using `impl Into<T>` trait bound
292/// - `#[set(pub, type(AsRef<[u8]>))]` - Generates a setter with `impl AsRef<[u8]>` parameter type
293///
294/// # Parameter Type Conversion
295/// Setters support flexible parameter type conversion through trait bounds:
296/// - `type(AsRef<T>)` - Accepts any type implementing `AsRef<T>` and converts using `.as_ref().to_owned()`
297/// - `type(Into<T>)` - Accepts any type implementing `Into<T>` and converts using `.into()`
298/// - `type(CustomTrait<T>)` - Accepts any type implementing the specified custom trait bound
299///
300/// # Examples
301///
302/// ## Basic Usage
303///
304/// ```rust
305/// use lombok_macros::*;
306///
307/// #[derive(Setter, Debug, Clone)]
308/// struct BasicStruct {
309///     #[set(pub)]
310///     name: String,
311///     #[set(pub(crate))]
312///     value: i32,
313///     #[set(private)]
314///     secret: String,
315/// }
316/// let mut basic = BasicStruct {
317///     name: "initial".to_string(),
318///     value: 0,
319///     secret: "hidden".to_string(),
320/// };
321/// basic.set_name("updated".to_string());
322/// basic.set_value(42);
323/// assert_eq!(basic.name, "updated");
324/// assert_eq!(basic.value, 42);
325/// ```
326///
327/// ## Parameter Type Conversion
328///
329/// ```rust
330/// use lombok_macros::*;
331///
332/// #[derive(Setter, Debug, Clone)]
333/// struct ConversionStruct {
334///     #[set(pub, type(AsRef<str>))]
335///     name: String,
336///     #[set(pub, type(Into<i32>))]
337///     value: i32,
338///     #[set(pub, type(AsRef<[u8]>))]
339///     data: Vec<u8>,
340/// }
341///
342/// let mut conversion = ConversionStruct {
343///     name: "initial".to_string(),
344///     value: 0,
345///     data: vec![1, 2, 3],
346/// };
347///
348/// conversion.set_name("updated");
349/// assert_eq!(conversion.name, "updated");
350///
351/// conversion.set_value(1u8);
352/// assert_eq!(conversion.value, 1);
353///
354/// conversion.set_data(&[4, 5, 6]);
355/// assert_eq!(conversion.data, vec![4, 5, 6]);
356/// ```
357///
358/// ## Tuple Structs
359///
360/// ```rust
361/// use lombok_macros::*;
362///
363/// #[derive(Setter, Debug, Clone)]
364/// struct TupleStruct(
365///     #[set(pub)] String,
366///     #[set(pub)] i32,
367/// );
368/// let mut tuple = TupleStruct("hello".to_string(), 1);
369/// tuple.set_0("world".to_string());
370/// tuple.set_1(100);
371/// assert_eq!(tuple.0, "world");
372/// assert_eq!(tuple.1, 100);
373/// ```
374#[proc_macro_derive(Setter, attributes(set))]
375pub fn setter(input: TokenStream) -> TokenStream {
376    inner_lombok_data(input, false, false, true)
377}
378
379/// A procedural macro that combines getter, mutable getter, and setter functionality in a single derive.
380///
381/// This macro derives all three types of accessor methods (getters, mutable getters, and setters)
382/// for struct and enum fields, providing comprehensive data manipulation capabilities with
383/// configurable visibility and behavior options.
384///
385/// # Supported Attributes
386/// - `#[get(...)]` - Controls getter generation (supports `reference`, `clone`, `copy`, `deref` options)
387/// - `#[get_mut(...)]` - Controls mutable getter generation
388/// - `#[set(...)]` - Controls setter generation (supports parameter type conversion with `type(AsRef<T>)`, `Into`, etc.)
389///
390/// # Visibility Control
391/// Each attribute supports the same visibility options:
392/// - `pub` - Public access
393/// - `pub(crate)` - Crate-level access
394/// - `pub(super)` - Parent module access
395/// - `private` - Private access
396///
397/// # Examples
398///
399/// ## Basic Combination
400///
401/// ```rust
402/// use lombok_macros::*;
403///
404/// #[derive(Data, Debug, Clone)]
405/// struct User {
406///     #[get(pub)]
407///     #[set(pub)]
408///     name: String,
409///     #[get(pub, type(clone))]
410///     #[set(pub)]
411///     email: String,
412///     #[get(pub, type(copy))]
413///     age: u32,
414///     #[get_mut(pub)]
415///     mutable_age: u32,
416/// }
417///
418/// let mut user = User {
419///     name: "Alice".to_string(),
420///     email: "alice@ltpp.vip".to_string(),
421///     age: 30,
422///     mutable_age: 25,
423/// };
424///
425/// let name_reference: &String = user.get_name();
426/// let email_clone: String = user.get_email();
427/// let age_copy: u32 = user.get_age();
428/// assert_eq!(*name_reference, "Alice");
429/// assert_eq!(email_clone, "alice@ltpp.vip");
430/// assert_eq!(age_copy, 30);
431///
432/// user.set_name("Bob".to_string());
433/// user.set_email("bob@ltpp.vip".to_string());
434///
435/// let updated_email: String = user.get_email();
436/// assert_eq!(updated_email, "bob@ltpp.vip");
437///
438/// let age_mutable_reference: &mut u32 = user.get_mut_mutable_age();
439/// *age_mutable_reference = 31;
440///
441/// assert_eq!(*age_mutable_reference, 31);
442/// ```
443///
444/// ## Multiple Field Types
445///
446/// ```rust
447/// use lombok_macros::*;
448///
449/// #[derive(Data, Debug, Clone)]
450/// struct ComplexStruct {
451///     #[get(pub)]
452///     id: i32,
453///     #[get(pub)]
454///     #[set(pub)]
455///     optional: Option<String>,
456///     #[get(pub, type(reference))]
457///     result: Result<i32, String>,
458///     #[get(pub(crate))]
459///     #[set(private)]
460///     internal_data: Vec<u8>,
461/// }
462///
463/// let mut complex = ComplexStruct {
464///     id: 1,
465///     optional: Some("value".to_string()),
466///     result: Ok(42),
467///     internal_data: vec![1, 2, 3],
468/// };
469///
470/// let id_reference: &i32 = complex.get_id();
471/// let optional_clone: String = complex.get_optional();
472/// let result_reference: &Result<i32, String> = complex.get_result();
473///
474/// assert_eq!(*id_reference, 1);
475/// assert_eq!(optional_clone, "value");
476/// assert_eq!(*result_reference, Ok(42));
477/// ```
478///
479/// ## Tuple Struct with Combined Accessors
480///
481/// ```rust
482/// use lombok_macros::*;
483///
484/// #[derive(Data, Debug, Clone)]
485/// struct Point(
486///     #[get(pub)] f64,
487///     #[get(pub, type(clone))]
488///     #[set(pub)] f64,
489/// );
490///
491/// let mut point = Point(1.0, 2.0);
492/// let x_coordinate: &f64 = point.get_0();
493/// let y_coordinate: f64 = point.get_1();
494///
495/// assert_eq!(*x_coordinate, 1.0);
496/// assert_eq!(y_coordinate, 2.0);
497///
498/// point.set_1(3.0);
499/// let updated_y_coordinate: f64 = point.get_1();
500/// assert_eq!(updated_y_coordinate, 3.0);
501/// ```
502#[proc_macro_derive(Data, attributes(get, get_mut, set))]
503pub fn data(input: TokenStream) -> TokenStream {
504    let mut result: TokenStream2 = TokenStream2::new();
505    let lombok_data: TokenStream = inner_lombok_data(input.clone(), true, true, true);
506    result.extend(
507        lombok_data
508            .to_string()
509            .parse::<TokenStream2>()
510            .unwrap_or_default(),
511    );
512    result.into()
513}
514
515/// A procedural macro that implements the `std::fmt::Display` trait for a type,
516/// using the standard debug format (`{:?}`) for formatting.
517///
518/// This macro derives the `Display` implementation for a type, allowing it to be formatted
519/// using `{:?}` in formatting macros. It uses the `inner_display_debug` function to generate
520/// the implementation with the standard debug format.
521///
522/// # Arguments
523/// - `input` - The input token stream representing the Rust item (struct, enum, etc.)
524///   for which the `Display` implementation will be generated.
525///
526/// # Returns
527/// - `TokenStream` - The generated `std::fmt::Display` implementation for the type
528///   using the standard debug format.
529#[proc_macro_derive(DisplayDebug)]
530pub fn display_debug(input: TokenStream) -> TokenStream {
531    inner_display_debug(input)
532}
533
534/// A procedural macro that implements the `std::fmt::Display` trait for a type,
535/// using the detailed debug format (`{:#?}`) for formatting.
536///
537/// This macro derives the `Display` implementation for a type, allowing it to be formatted
538/// using `{:#?}` in formatting macros. It uses the `inner_display_debug_format` function
539/// to generate the implementation with the detailed debug format.
540///
541/// # Arguments
542/// - `input` - The input token stream representing the Rust item (struct, enum, etc.)
543///   for which the `Display` implementation will be generated.
544///
545/// # Returns
546/// - `TokenStream` - The generated `std::fmt::Display` implementation for the type
547///   using the detailed debug format.
548#[proc_macro_derive(DisplayDebugFormat)]
549pub fn display_debug_format(input: TokenStream) -> TokenStream {
550    inner_display_debug_format(input)
551}
552
553/// A procedural macro that implements the `std::fmt::Debug` trait for a type,
554/// with support for the `#[debug(skip)]` attribute to skip specific fields.
555///
556/// This macro derives a custom Debug implementation that behaves like the standard
557/// library's Debug derive, but allows individual fields to be excluded from the
558/// debug output by annotating them with `#[debug(skip)]`.
559///
560/// # Supported Attributes
561/// - `#[debug(skip)]` - Excludes the field from the debug output
562///
563/// # Examples
564///
565/// ## Struct Example
566/// ```rust
567/// use lombok_macros::*;
568///
569/// #[derive(CustomDebug)]
570/// struct User {
571///     name: String,
572///     #[debug(skip)]
573///     password: String,
574///     email: String,
575/// }
576///
577/// let user = User {
578///     name: "Alice".to_string(),
579///     password: "secret123".to_string(),
580///     email: "alice@ltpp.vip".to_string(),
581/// };
582/// let expected_debug = "User { name: \"Alice\", email: \"alice@ltpp.vip\" }";
583/// assert_eq!(format!("{:?}", user), expected_debug);
584/// ```
585///
586/// ## Enum Example
587/// ```rust
588/// use lombok_macros::*;
589///
590/// #[derive(CustomDebug)]
591/// enum Response {
592///     Success { data: String },
593///     Error {
594///         message: String,
595///         #[debug(skip)]
596///         internal_code: u32,
597///     },
598/// }
599///
600/// let success = Response::Success { data: "Hello".to_string() };
601/// let error = Response::Error { message: "Failed".to_string(), internal_code: 500 };
602/// let expected_success = "Success { data: \"Hello\" }";
603/// let expected_error = "Error { message: \"Failed\" }";
604/// assert_eq!(format!("{:?}", success), expected_success);
605/// assert_eq!(format!("{:?}", error), expected_error);
606/// ```
607///
608/// # Arguments
609/// - `input` - The input token stream representing the Rust item (struct, enum, etc.)
610///   for which the Debug implementation will be generated.
611///
612/// # Returns
613/// - `TokenStream` - The generated `std::fmt::Debug` implementation for the type
614///   that respects the `#[debug(skip)]` attribute.
615#[proc_macro_derive(CustomDebug, attributes(debug))]
616pub fn custom_debug(input: TokenStream) -> TokenStream {
617    inner_custom_debug(input)
618}
619
620/// A procedural macro that generates a constructor function for structs.
621///
622/// This macro automatically generates a `new` function that takes all non-skipped fields
623/// as parameters and returns a new instance of the struct. Fields marked with `#[new(skip)]`
624/// will be initialized with their default values.
625///
626/// # Supported Attributes
627/// - `#[new(skip)]` - Excludes the field from constructor parameters and uses default initialization
628/// - `#[new(pub)]` - Generates a public constructor  
629/// - `#[new(pub(crate))]` - Generates a crate-visible constructor  
630/// - `#[new(pub(super))]` - Generates a constructor visible to parent module  
631/// - `#[new(private)]` - Generates a private constructor
632///
633/// # Default Behavior
634/// - The generated constructor is `pub` by default
635/// - All fields are included in the constructor unless marked with `#[new(skip)]`
636/// - Skipped fields are initialized using `Default::default()`
637///
638/// # Examples
639///
640/// ## Basic Usage
641/// ```rust
642/// use lombok_macros::*;
643///
644/// #[derive(New)]
645/// struct Person {
646///     name: String,
647///     age: u32,
648/// }
649///
650/// let person = Person::new("Alice".to_string(), 30);
651/// assert_eq!(person.name, "Alice");
652/// assert_eq!(person.age, 30);
653/// ```
654///
655/// ## With Skip Attribute
656/// ```rust
657/// use lombok_macros::*;
658///
659/// #[derive(New)]
660/// struct User {
661///     username: String,
662///     email: String,
663///     #[new(skip)]
664///     created_at: String,
665/// }
666///
667/// let user = User::new("alice".to_string(), "alice@ltpp.vip".to_string());
668/// assert_eq!(user.username, "alice");
669/// assert_eq!(user.email, "alice@ltpp.vip");
670/// assert_eq!(user.created_at, "");
671/// ```
672///
673/// ## With Custom Visibility
674/// ```rust
675/// use lombok_macros::*;
676///
677/// #[derive(New)]
678/// #[new(pub(crate))]
679/// struct InternalStruct {
680///     value: i32,
681/// }
682///
683/// let internal = InternalStruct::new(42);
684/// assert_eq!(internal.value, 42);
685/// ```
686///
687/// ## Tuple Structs
688/// ```rust
689/// use lombok_macros::*;
690///
691/// #[derive(New)]
692/// struct Point(
693///     f64,
694///     f64,
695/// );
696///
697/// let origin = Point::new(0.0, 0.0);
698/// assert_eq!(origin.0, 0.0);
699/// assert_eq!(origin.1, 0.0);
700/// ```
701///
702/// ## Generic Types
703/// ```rust
704/// use lombok_macros::*;
705///
706/// #[derive(New)]
707/// struct Container<T: Default + Clone> {
708///     data: T,
709///     #[new(skip)]
710///     count: usize,
711/// }
712///
713/// let container = Container::new("data".to_string());
714/// assert_eq!(container.data, "data");
715/// assert_eq!(container.count, 0);
716/// ```
717///
718/// # Arguments
719/// - `input` - The input token stream representing the struct for which to generate the constructor.
720///
721/// # Returns
722/// - `TokenStream` - The generated constructor implementation.
723#[proc_macro_derive(New, attributes(new))]
724pub fn new(input: TokenStream) -> TokenStream {
725    let derive_input: DeriveInput = parse_macro_input!(input as DeriveInput);
726    let visibility: Visibility = parse_new_visibility(&derive_input);
727    inner_new_constructor(&derive_input, visibility)
728}