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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/// Constructs an anonymous struct,
/// which implements all the accessor traits for its fields.
///
/// # Syntax
///
/// Here is the entire syntax for this macro:
///
/// ```
/// # use structural::make_struct;
///
/// # let foo=();
/// # let _=
/// make_struct!{
/// // This is an inner attribute,which is applied to the struct declaration.
/// // In this case it's deriving `Debug` for the struct.
/// #![derive(Debug)]
///
/// // This is an attribute on the first field.
/// #[doc="you must put attributes for the first field after the inner attributes"]
/// size_cm:0,
/// place:"Anctartica",
/// foo, // This initializes a `foo` field with the `foo` variable.
/// }
/// # ;
/// ```
///
/// # Example
///
/// ```rust
/// use structural::{StructuralExt,make_struct,structural_alias,fp};
///
/// use std::fmt::Debug;
///
/// structural_alias!{
/// pub trait Runner{
/// name:String,
/// stamina:u32,
/// }
/// }
///
/// // Everything below could be on a separate crate (ignoring imports)
///
/// # fn main(){
///
/// fn get_runner(this:&(impl Runner+Debug) ){
/// assert_eq!( this.field_(fp!(name)).as_str(), "hello","{:?}",this);
/// assert_eq!( this.field_(fp!(stamina)), &100,"{:?}",this);
/// }
///
/// get_runner(&make_struct!{
/// #![derive(Debug)]
/// name:"hello".into(),
/// stamina:100,
/// });
///
///
/// fn ret_get_runner(name:String)->impl Runner+Clone{
/// make_struct!{
/// #![derive(Clone)]
/// name,
/// stamina:4_000_000_000,
/// }
/// }
///
/// {
/// let runner=ret_get_runner("hello".into());
///
/// assert_eq!( runner.field_(fp!(name)).as_str(), "hello" );
/// assert_eq!( runner.field_(fp!(stamina)), &4_000_000_000 );
///
/// let (name,stamina) = runner.into_fields(fp!( name, stamina ));
/// assert_eq!( name, "hello" );
/// assert_eq!( stamina, 4_000_000_000 );
/// }
///
///
/// # }
///
/// ```
}
$*
$crate_private_impl_getters_for_derive_struct!
}
__Anonymous_Struct
}
});
}