Skip to main content

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