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
//! # get_set_macro
//!
//! A procedural macro to generate customizable getters and setters for your Rust structs.
//!
//! ## Installation
//!
//! Run `cargo add get_set_macro`
//!
//! ## Example Usage
//!
//! ```rust
//! use get_set_macro::get_set;
//!
//! // By default, each field in `Example` will recieve a getter with the #[inline(always)] attribute.
//! // Here the `default` is applied to the `get`, so the global get will be #[inline(always)].
//! #[get_set(default(inline_always, vis = "pub"), get)]
//! struct Example {
//! // This field will not recieve the default getter.
//! #[gsflags(skip)]
//! skipped: u8,
//!
//! // Despite only having the `set` flag, this member will recieve both a getter and a setter,
//! // each with pub visibility and each being #[inline(always)]
//! #[gsflags(set)]
//! name: String,
//!
//! // Since u32's are trivially copyable,
//! // there is no need to pass this value by reference and so instead we will pass it by value.
//! // This flag has also inhereted the default `inline_always`, so this `get_copy` will be #[inline(always)].
//! // If we wanted to override the defaults, adding `default(noinline, vis = "")` anywhere
//! // in the gsflags body would change the defaults to having no inline attribute and inherited (private) visibility.
//! // If we didn't want this to override the default get(_ref), we could change
//! // `get_copy` to `get_copy(rename = "get_age_copy")`,
//! // which would simply create a new method that returned a copy.
//! #[gsflags(get_copy)]
//! age: u32,
//! }
//!
//! // Has functionality
//! fn main() {
//! let mut example = Example {
//! skipped: 8,
//! name: "ExampleName".to_string(),
//! age: 69,
//! };
//!
//! // The following would error as there is no method named `get_skipped`
//! // assert_eq!(8, example.get_skipped());
//!
//! // The getters and setters of `name`
//! assert_eq!("ExampleName".to_string(), *example.get_name());
//! example.set_name("NewName".to_string());
//! assert_eq!("NewName".to_string(), *example.get_name());
//!
//! assert_eq!(69, example.get_age());
//! }
//! ```
//!
//! ## See Also
//!
//! - [Crate on crates.io](https://crates.io/crates/get_set_macro)
//! - [Source on GitHub](https://github.com/Orkking2/get_set_macro)
//! - [More examples](https://github.com/Orkking2/get_set_proc_macro/tree/main/tests/ui)
use TokenStream;
use ;