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
//! # Quick Macros
//!
//! This crate provides simple macros:
//! - **Derive**
//! - FieldNames - macro used for generating functions returning a name of a field
//!
use TokenStream;
use proc_macro_error;
use ;
/// Generates methods for retrieving field names of a struct as string literals.
///
/// This function is used as part of a procedural macro. It takes a struct definition,
/// extracts its named fields, and generates a method for each field. Each generated method
/// follows the naming pattern `nameof_<field_name>()`, which returns the field name as a static string.
///
/// # Example
/// ```
/// use quick_macros::FieldNames;
///
/// #[derive(FieldNames)]
/// struct Person {
/// name: String,
/// age: u32,
/// }
///
/// assert_eq!(Person::nameof_name(), "name");
/// assert_eq!(Person::nameof_age(), "age");
/// ```
///
/// # Panics
/// - If the macro is applied to a non-struct type (e.g., an enum or union), it will panic.
/// Generates a constructor method for a struct, allowing instantiation with all fields.
///
/// This procedural macro derives an implementation of a new method for a struct.
/// The generated method takes each field of the struct as a parameter and returns an instance
/// of the struct with those fields initialized.
///
/// # Example
/// ```
/// use quick_macros::FullCtor;
///
/// #[derive(FullCtor)]
/// struct Person {
/// name: String,
/// age: u32,
/// }
///
/// let person = Person::new("Alice".to_string(), 30);
/// assert_eq!(person.name, "Alice");
/// assert_eq!(person.age, 30);
/// ```
///
/// # Panics
/// - If the macro is applied to a non-struct type (e.g., an enum or union), it will panic.