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::{
19 Delimiter, TokenStream as TokenStream2, TokenTree as TokenTree2, token_stream::IntoIter,
20 },
21 quote::{ToTokens, format_ident, quote},
22 syn::{
23 Data, DeriveInput, Field, Fields, GenericArgument, GenericParam, Generics, Ident, Index,
24 Lifetime, PathArguments, Type, TypeParam, Variant, WhereClause, parse_macro_input, parse2,
25 },
26};
27
28use std::{
29 collections::HashMap,
30 fmt::{Display, Formatter},
31 iter::Peekable,
32 str::FromStr,
33};
34
35/// A procedural macro that automatically generates getter methods for struct and enum fields.
36///
37/// This macro derives getter methods with configurable visibility and return type behavior.
38/// The generated getters can return either references to field values or cloned copies,
39/// with support for Option and Result types.
40///
41/// # Supported Attributes
42/// - `#[get(pub)]` - Generates a public getter with reference return type
43/// - `#[get(pub)]` - Generates a public getter that returns a reference (`&T`)
44/// - `#[get(pub, clone)]` - Generates a public getter that returns a cloned value (`T`)
45/// - `#[get(pub, copy)]` - Generates a public getter that returns a copy of the field value (`self.field`) for Copy types
46/// - `#[get(pub, deref)]` - Generates a public getter that returns a dereferenced value (`*field`) with enhanced match control for Option/Result types
47/// - `#[get(pub(crate))]` - Generates a crate-visible getter
48/// - `#[get(private)]` - Generates a private getter
49///
50/// # Return Type Behavior
51/// - `reference` - Returns `&T` - a reference to the field value
52/// - `clone` - Returns `T` - a cloned copy of the field value
53/// - `copy` - Returns `T` - a copy of the field value (`self.field`) for types implementing Copy trait
54/// - `deref` - Returns dereferenced values with enhanced match control:
55/// - `Option<T>` → `T` with detailed None panic messages
56/// - `Result<T, E>` → `T` with detailed Err panic messages
57/// - `Box<T>` → `T` by dereferencing the box
58/// - `Rc<T>` → `T` by cloning the inner value
59/// - `Arc<T>` → `T` by cloning the inner value
60/// - Other types → `T` by dereferencing
61/// - Default behavior: Returns `&T` for non-Option/Result types, `T` for Option/Result types
62///
63/// # Default Behavior Details
64/// - **Non-Option/Result types**: Returns `&T` (reference to field)
65/// - **Option/Result types**: Returns `T` (cloned value) to avoid exposing internal references
66/// - This ensures safe access patterns while maintaining performance for common use cases
67///
68/// # Examples
69///
70/// ## Basic Usage
71///
72/// ```rust
73/// use lombok_macros::*;
74///
75/// #[derive(Clone, Getter)]
76/// struct BasicStruct {
77/// #[get(pub)]
78/// name: String,
79/// #[get(pub)]
80/// description: String,
81/// #[get(pub, type(clone))]
82/// data: Vec<i32>,
83/// #[get(pub, type(copy))]
84/// count: i32,
85/// }
86///
87/// let basic = BasicStruct {
88/// name: "test".to_string(),
89/// description: "description".to_string(),
90/// data: vec![1, 2, 3],
91/// count: 42,
92/// };
93/// let name_ref: &String = basic.get_name();
94/// let description_ref: &String = basic.get_description();
95/// let data_clone: Vec<i32> = basic.get_data();
96/// let count_copy: i32 = basic.get_count();
97/// assert_eq!(*name_ref, "test");
98/// assert_eq!(*description_ref, "description");
99/// assert_eq!(data_clone, vec![1, 2, 3]);
100/// assert_eq!(count_copy, 42);
101/// ```
102///
103/// ## Option and Result Types
104///
105/// ```rust
106/// use lombok_macros::*;
107///
108/// #[derive(Clone, Getter)]
109/// struct OptionalStruct {
110/// #[get(pub)]
111/// optional: Option<String>,
112/// #[get(pub)]
113/// optional_ref: Option<String>,
114/// #[get(pub)]
115/// result: Result<String, String>,
116/// }
117///
118/// let opt_struct = OptionalStruct {
119/// optional: Some("value".to_string()),
120/// optional_ref: Some("ref_value".to_string()),
121/// result: Ok("success".to_string()),
122/// };
123/// let optional_value: String = opt_struct.get_optional();
124/// let optional_reference: String = opt_struct.get_optional_ref();
125/// let result_value: String = opt_struct.get_result();
126/// assert_eq!(optional_value, "value");
127/// assert_eq!(optional_reference, "ref_value");
128/// assert_eq!(result_value, "success");
129/// ```
130///
131/// ## Tuple Structs
132///
133/// ```rust
134/// use lombok_macros::*;
135///
136/// #[derive(Clone, Getter)]
137/// struct TupleStruct(
138/// #[get(pub)] String,
139/// #[get(pub, type(clone))] Vec<i32>,
140/// );
141///
142/// let tuple = TupleStruct("hello".to_string(), vec![1, 2, 3]);
143/// let field0: &String = tuple.get_0();
144/// let field1: Vec<i32> = tuple.get_1();
145/// assert_eq!(*field0, "hello");
146/// assert_eq!(field1, vec![1, 2, 3]);
147/// ```
148///
149/// ## Copy Return Type
150///
151/// ```rust
152/// use lombok_macros::*;
153///
154/// #[derive(Clone, Getter)]
155/// struct CopyStruct {
156/// #[get(pub, type(copy))]
157/// value: i32,
158/// #[get(pub, type(copy))]
159/// flag: bool,
160/// #[get(pub, type(copy))]
161/// count: u64,
162/// }
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(Clone, Getter)]
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///
196/// let deref_struct = DerefStruct {
197/// optional: Some(true),
198/// result: Ok("success".to_string()),
199/// boxed_value: Box::new(100),
200/// rc_value: std::rc::Rc::new("test".to_string()),
201/// arc_value: std::sync::Arc::new(vec![1, 2, 3]),
202/// };
203/// let optional_value: bool = deref_struct.get_optional();
204/// let result_value: String = deref_struct.get_result();
205/// let boxed_value: i32 = deref_struct.get_boxed_value();
206/// let rc_value: String = deref_struct.get_rc_value();
207/// let arc_value: Vec<u8> = deref_struct.get_arc_value();
208/// assert_eq!(optional_value, true);
209/// assert_eq!(result_value, "success");
210/// assert_eq!(boxed_value, 100);
211/// assert_eq!(rc_value, "test");
212/// assert_eq!(arc_value, vec![1, 2, 3]);
213/// ```
214///
215/// ## Generics and Lifetimes
216///
217/// ```rust
218/// use lombok_macros::*;
219///
220/// #[derive(Clone, Getter)]
221/// struct GenericStruct<'a, T: Clone> {
222/// #[get(pub)]
223/// value: &'a T,
224/// #[get(pub, type(clone))]
225/// owned: T,
226/// }
227///
228/// let data = 42;
229/// let generic = GenericStruct {
230/// value: &data,
231/// owned: 42,
232/// };
233/// let value_ref: &i32 = generic.get_value();
234/// let owned_clone: i32 = generic.get_owned();
235/// assert_eq!(*value_ref, 42);
236/// assert_eq!(owned_clone, 42);
237/// ```
238#[proc_macro_derive(Getter, attributes(get))]
239pub fn getter(input: TokenStream) -> TokenStream {
240 inner_lombok_data(input, true, false, false)
241}
242
243/// A procedural macro that automatically generates mutable getter methods for struct and enum fields.
244///
245/// This macro derives mutable getter methods that provide mutable references to field values,
246/// allowing modification of the struct's fields while maintaining proper borrowing semantics.
247///
248/// # Supported Attributes
249/// - `#[get_mut(pub)]` - Generates a public mutable getter
250/// - `#[get_mut(pub(crate))]` - Generates a crate-visible mutable getter
251/// - `#[get_mut(pub(super))]` - Generates a mutable getter visible to parent module
252/// - `#[get_mut(private)]` - Generates a private mutable getter
253///
254/// # Example
255///
256/// ```rust
257/// use lombok_macros::*;
258///
259/// #[derive(Clone, GetterMut)]
260/// struct StructWithLifetimes<'a, 'b, T: Clone> {
261/// #[get_mut(pub(crate))]
262/// list: Vec<String>,
263/// #[get_mut(pub(crate))]
264/// optional_lifetime_a: Option<&'a T>,
265/// optional_lifetime_b: Option<&'b str>,
266/// }
267///
268/// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
269/// let mut struct_with_lifetimes: StructWithLifetimes<usize> = StructWithLifetimes {
270/// list: list.clone(),
271/// optional_lifetime_a: None,
272/// optional_lifetime_b: None,
273/// };
274/// let mut list_reference: &mut Vec<String> = struct_with_lifetimes.get_mut_list();
275/// list_reference.push("new_item".to_string());
276/// assert_eq!(*list_reference, vec!["hello".to_string(), "world".to_string(), "new_item".to_string()]);
277/// ```
278#[proc_macro_derive(GetterMut, attributes(get_mut))]
279pub fn getter_mut(input: TokenStream) -> TokenStream {
280 inner_lombok_data(input, false, true, false)
281}
282
283/// A procedural macro that automatically generates setter methods for struct and enum fields.
284///
285/// This macro derives setter methods that allow modification of struct fields with
286/// configurable visibility and parameter type conversion options.
287///
288/// # Supported Attributes
289/// - `#[set(pub)]` - Generates a public setter
290/// - `#[set(pub(crate))]` - Generates a crate-visible setter
291/// - `#[set(pub(super))]` - Generates a setter visible to parent module
292/// - `#[set(private)]` - Generates a private setter
293/// - `#[set(pub, type(AsRef<str>))]` - Generates a setter with custom parameter type conversion
294/// - `#[set(pub, Into)]` - Generates a setter using `impl Into<T>` trait bound
295/// - `#[set(pub, type(AsRef<[u8]>))]` - Generates a setter with `impl AsRef<[u8]>` parameter type
296///
297/// # Parameter Type Conversion
298/// Setters support flexible parameter type conversion through trait bounds:
299/// - `type(AsRef<T>)` - Accepts any type implementing `AsRef<T>` and converts using `.as_ref().to_owned()`
300/// - `type(Into<T>)` - Accepts any type implementing `Into<T>` and converts using `.into()`
301/// - `type(CustomTrait<T>)` - Accepts any type implementing the specified custom trait bound
302///
303/// # Examples
304///
305/// ## Basic Usage
306///
307/// ```rust
308/// use lombok_macros::*;
309///
310/// #[derive(Clone, Debug, Setter)]
311/// struct BasicStruct {
312/// #[set(pub)]
313/// name: String,
314/// #[set(pub(crate))]
315/// value: i32,
316/// #[set(private)]
317/// secret: String,
318/// }
319///
320/// let mut basic = BasicStruct {
321/// name: "initial".to_string(),
322/// value: 0,
323/// secret: "hidden".to_string(),
324/// };
325/// basic.set_name("updated".to_string());
326/// basic.set_value(42);
327/// assert_eq!(basic.name, "updated");
328/// assert_eq!(basic.value, 42);
329/// ```
330///
331/// ## Parameter Type Conversion
332///
333/// ```rust
334/// use lombok_macros::*;
335///
336/// #[derive(Clone, Debug, Setter)]
337/// struct ConversionStruct {
338/// #[set(pub, type(AsRef<str>))]
339/// name: String,
340/// #[set(pub, type(Into<i32>))]
341/// value: i32,
342/// #[set(pub, type(AsRef<[u8]>))]
343/// data: Vec<u8>,
344/// }
345///
346/// let mut conversion = ConversionStruct {
347/// name: "initial".to_string(),
348/// value: 0,
349/// data: vec![1, 2, 3],
350/// };
351///
352/// conversion.set_name("updated");
353/// assert_eq!(conversion.name, "updated");
354///
355/// conversion.set_value(1u8);
356/// assert_eq!(conversion.value, 1);
357///
358/// conversion.set_data(&[4, 5, 6]);
359/// assert_eq!(conversion.data, vec![4, 5, 6]);
360/// ```
361///
362/// ## Tuple Structs
363///
364/// ```rust
365/// use lombok_macros::*;
366///
367/// #[derive(Clone, Debug, Setter)]
368/// struct TupleStruct(
369/// #[set(pub)] String,
370/// #[set(pub)] i32,
371/// );
372///
373/// let mut tuple = TupleStruct("hello".to_string(), 1);
374/// tuple.set_0("world".to_string());
375/// tuple.set_1(100);
376/// assert_eq!(tuple.0, "world");
377/// assert_eq!(tuple.1, 100);
378/// ```
379#[proc_macro_derive(Setter, attributes(set))]
380pub fn setter(input: TokenStream) -> TokenStream {
381 inner_lombok_data(input, false, false, true)
382}
383
384/// A procedural macro that combines getter, mutable getter, and setter functionality in a single derive.
385///
386/// This macro derives all three types of accessor methods (getters, mutable getters, and setters)
387/// for struct and enum fields, providing comprehensive data manipulation capabilities with
388/// configurable visibility and behavior options.
389///
390/// # Supported Attributes
391/// - `#[get(...)]` - Controls getter generation (supports `reference`, `clone`, `copy`, `deref` options)
392/// - `#[get_mut(...)]` - Controls mutable getter generation
393/// - `#[set(...)]` - Controls setter generation (supports parameter type conversion with `type(AsRef<T>)`, `Into`, etc.)
394///
395/// # Visibility Control
396/// Each attribute supports the same visibility options:
397/// - `pub` - Public access
398/// - `pub(crate)` - Crate-level access
399/// - `pub(super)` - Parent module access
400/// - `private` - Private access
401///
402/// # Examples
403///
404/// ## Basic Combination
405///
406/// ```rust
407/// use lombok_macros::*;
408///
409/// #[derive(Clone, Data, Debug)]
410/// struct User {
411/// #[get(pub)]
412/// #[set(pub)]
413/// name: String,
414/// #[get(pub, type(clone))]
415/// #[set(pub)]
416/// email: String,
417/// #[get(pub, type(copy))]
418/// age: u32,
419/// #[get_mut(pub)]
420/// mutable_age: u32,
421/// }
422///
423/// let mut user = User {
424/// name: "Alice".to_string(),
425/// email: "alice@ltpp.vip".to_string(),
426/// age: 30,
427/// mutable_age: 25,
428/// };
429/// let name_reference: &String = user.get_name();
430/// let email_clone: String = user.get_email();
431/// let age_copy: u32 = user.get_age();
432/// assert_eq!(*name_reference, "Alice");
433/// assert_eq!(email_clone, "alice@ltpp.vip");
434/// assert_eq!(age_copy, 30);
435///
436/// user.set_name("Bob".to_string());
437/// user.set_email("bob@ltpp.vip".to_string());
438/// let updated_email: String = user.get_email();
439/// assert_eq!(updated_email, "bob@ltpp.vip");
440///
441/// (*user.get_mut_mutable_age() = 31);
442///
443/// assert_eq!(*user.get_mutable_age(), 31);
444/// ```
445///
446/// ## Multiple Field Types
447///
448/// ```rust
449/// use lombok_macros::*;
450///
451/// #[derive(Clone, Data, Debug)]
452/// struct ComplexStruct {
453/// #[get(pub)]
454/// id: i32,
455/// #[get(pub)]
456/// #[set(pub)]
457/// optional: Option<String>,
458/// #[get(pub)]
459/// result: Result<i32, String>,
460/// #[get(pub(crate))]
461/// #[set(private)]
462/// internal_data: Vec<u8>,
463/// }
464///
465/// let mut complex = ComplexStruct {
466/// id: 1,
467/// optional: Some("value".to_string()),
468/// result: Ok(42),
469/// internal_data: vec![1, 2, 3],
470/// };
471///
472/// let id_reference: &i32 = complex.get_id();
473/// let optional_clone: String = complex.get_optional();
474/// let result_reference: i32 = complex.get_result();
475/// assert_eq!(*id_reference, 1);
476/// assert_eq!(optional_clone, "value");
477/// assert_eq!(result_reference, 42);
478/// ```
479///
480/// ## Tuple Struct with Combined Accessors
481///
482/// ```rust
483/// use lombok_macros::*;
484///
485/// #[derive(Clone, Data, Debug)]
486/// struct Point(
487/// #[get(pub)] f64,
488/// #[get(pub, type(clone))]
489/// #[set(pub)] f64,
490/// );
491///
492/// let mut point = Point(1.0, 2.0);
493/// let x_coordinate: &f64 = point.get_0();
494/// let y_coordinate: f64 = point.get_1();
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}