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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use Ordering;
use fmt;
use ;
use PhantomData;
use crateGodotShape;
use crate;
use crate;
/// A zero-sized type for creating a property without a backing field, accessible only through custom getter/setter functions.
///
/// This must be used in a struct deriving [`GodotClass`](../register/derive.GodotClass.html) and requires that the field has
/// an explicit [`#[var]` attribute](../register/derive.GodotClass.html#register-properties--var) with a custom getter,
/// and optionally a custom setter. Both getter and setter operate on the specified type `T`.
///
/// (Note that write-only properties, with a setter but not a getter, are not currently supported.
/// Godot doesn't fully support them either, silently returning null instead of an error if the property is being read.)
///
/// # Example
///
/// Suppose you have a field `text` whose value you want to keep as a Rust `String` rather than a Godot `GString`,
/// accepting the performance penalty for conversions whenever the property is accessed from Godot:
///
/// ```
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Banner {
/// #[var(get = get_text, set = set_text)]
/// text: PhantomVar<GString>,
///
/// text_string: String,
/// }
///
/// #[godot_api]
/// impl Banner {
/// #[func]
/// fn get_text(&self) -> GString {
/// GString::from(&self.text_string)
/// }
///
/// #[func]
/// fn set_text(&mut self, text: GString) {
/// self.text_string = String::from(&text);
/// }
/// }
/// ```
///
/// This field can now be accessed from GDScript as `banner.text`.
///
/// ## Export Tool Button
///
/// `PhantomVar<Callable>` is also used with
/// [`#[export_tool_button]`](../derive.GodotClass.html#export-tool-button), see its docs for details.
// Bounds for T are somewhat un-idiomatically directly on the type, rather than impls.
// This improves error messages in IDEs when using the type as a field.
;
// `PhantomVar` supports only part of `Var`, but it has to implement it, otherwise we cannot implement `Export` either.
// The `GodotClass` derive macro should ensure that the `Var` implementation is not used.
// Reuse values from `T`, if any.
// Like `PhantomData` from the Rust standard library, `PhantomVar` implements many common traits like `Eq` and `Hash`
// to allow these traits to be derived on containing structs as well.
// SAFETY: This type contains no data.
unsafe
// SAFETY: This type contains no data.
unsafe
/// This type exists only as a place to add `compile_fail` doctests for `PhantomVar`, which do not need to be in the public documentation.
///
/// Omitting the `#[var]` attribute is an error:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Oops {
/// missing_var: PhantomVar<i64>,
/// }
/// ```
///
/// Declaring `#[var]` without a getter and/or setter is an error:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Oops {
/// #[var]
/// missing_get_set: PhantomVar<i64>,
/// }
/// ```
///
/// Declaring `#[var]` without a getter is an error:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Oops {
/// #[var(set = setter)]
/// missing_get: PhantomVar<i64>,
/// }
///
/// #[godot_api]
/// impl Oops {
/// #[func]
/// fn setter(&mut self, value: i64) {
/// }
/// }
/// ```
///
/// Declaring `#[var]` with a default getter is an error:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Oops {
/// #[var(get, set = setter)]
/// default_get: PhantomVar<i64>,
/// }
///
/// #[godot_api]
/// impl Oops {
/// #[func]
/// fn setter(&mut self, value: i64) {
/// }
/// }
/// ```
///
/// Declaring `#[var]` with a default setter is an error:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Oops {
/// #[var(get = getter, set)]
/// missing_set: PhantomVar<i64>,
/// }
///
/// #[godot_api]
/// impl Oops {
/// #[func]
/// fn getter(&self) -> i64 {
/// 0
/// }
/// }
/// ```
;