@@ -81,8 +81,7 @@ use crate::util::ident;
81
81
/// your `struct`:
82
82
///
83
83
/// ```
84
- /// use godot::prelude::*;
85
- ///
84
+ /// # use godot::prelude::*;
86
85
/// #[derive(GodotClass)]
87
86
/// #[class(base = Node2D)]
88
87
/// struct MyStruct {
@@ -94,8 +93,7 @@ use crate::util::ident;
94
93
/// your object accordingly. You can access it through `self.base()` and `self.base_mut()` methods.
95
94
///
96
95
/// ```
97
- /// use godot::prelude::*;
98
- ///
96
+ /// # use godot::prelude::*;
99
97
/// #[derive(GodotClass)]
100
98
/// #[class(base = Node2D)]
101
99
/// struct MyStruct {
@@ -116,8 +114,7 @@ use crate::util::ident;
116
114
/// To create a property, you can use the `#[var]` annotation:
117
115
///
118
116
/// ```
119
- /// use godot::prelude::*;
120
- ///
117
+ /// # use godot::prelude::*;
121
118
/// #[derive(GodotClass)]
122
119
/// struct MyStruct {
123
120
/// #[var]
@@ -134,8 +131,7 @@ use crate::util::ident;
134
131
/// `#[export(get = ..., set = ...)]`:
135
132
///
136
133
/// ```
137
- /// use godot::prelude::*;
138
- ///
134
+ /// # use godot::prelude::*;
139
135
/// #[derive(GodotClass)]
140
136
/// struct MyStruct {
141
137
/// #[var(get = get_my_field, set = set_my_field)]
@@ -161,8 +157,7 @@ use crate::util::ident;
161
157
/// generated getter or setter in these cases anyway, use `get` or `set` without a value:
162
158
///
163
159
/// ```
164
- /// use godot::prelude::*;
165
- ///
160
+ /// # use godot::prelude::*;
166
161
/// #[derive(GodotClass)]
167
162
/// struct MyStruct {
168
163
/// // Default getter, custom setter.
@@ -182,8 +177,7 @@ use crate::util::ident;
182
177
/// For exporting properties to the editor, you can use the `#[export]` attribute:
183
178
///
184
179
/// ```
185
- /// use godot::prelude::*;
186
- ///
180
+ /// # use godot::prelude::*;
187
181
/// #[derive(GodotClass)]
188
182
/// struct MyStruct {
189
183
/// #[export]
@@ -206,8 +200,7 @@ use crate::util::ident;
206
200
/// As an example of some different export attributes:
207
201
///
208
202
/// ```
209
- /// use godot::prelude::*;
210
- ///
203
+ /// # use godot::prelude::*;
211
204
/// #[derive(GodotClass)]
212
205
/// struct MyStruct {
213
206
/// // @export
@@ -249,8 +242,7 @@ use crate::util::ident;
249
242
/// the export attributes.
250
243
///
251
244
/// ```
252
- /// use godot::prelude::*;
253
- ///
245
+ /// # use godot::prelude::*;
254
246
/// const MAX_HEALTH: f64 = 100.0;
255
247
///
256
248
/// #[derive(GodotClass)]
@@ -267,8 +259,7 @@ use crate::util::ident;
267
259
/// `hint`, `hint_string`, and `usage_flags` keys in the attribute:
268
260
///
269
261
/// ```
270
- /// use godot::prelude::*;
271
- ///
262
+ /// # use godot::prelude::*;
272
263
/// #[derive(GodotClass)]
273
264
/// struct MyStruct {
274
265
/// // Treated as an enum with two values: "One" and "Two"
@@ -289,8 +280,7 @@ use crate::util::ident;
289
280
/// It will be fundamentally reworked.
290
281
///
291
282
/// ```no_run
292
- /// use godot::prelude::*;
293
- ///
283
+ /// # use godot::prelude::*;
294
284
/// #[derive(GodotClass)]
295
285
/// struct MyClass {}
296
286
///
@@ -311,7 +301,7 @@ use crate::util::ident;
311
301
///
312
302
/// This is very similar to [GDScript's `@tool` feature](https://docs.godotengine.org/en/stable/tutorials/plugins/running_code_in_the_editor.html).
313
303
///
314
- /// # Editor Plugins
304
+ /// # Editor plugins
315
305
///
316
306
/// If you annotate a class with `#[class(editor_plugin)]`, it will be turned into an editor plugin. The
317
307
/// class must then inherit from `EditorPlugin`, and an instance of that class will be automatically added
@@ -325,13 +315,13 @@ use crate::util::ident;
325
315
/// This should usually be combined with `#[class(tool)]` so that the code you write will actually run in the
326
316
/// editor.
327
317
///
328
- /// # Class Renaming
318
+ /// # Class renaming
329
319
///
330
320
/// You may want to have structs with the same name. With Rust, this is allowed using `mod`. However in GDScript,
331
321
/// there are no modules, namespaces, or any such disambiguation. Therefore, you need to change the names before they
332
322
/// can get to Godot. You can use the `rename` key while defining your `GodotClass` for this.
333
323
///
334
- /// ```
324
+ /// ```no_run
335
325
/// mod animal {
336
326
/// # use godot::prelude::*;
337
327
/// #[derive(GodotClass)]
@@ -349,7 +339,7 @@ use crate::util::ident;
349
339
///
350
340
/// These classes will appear in the Godot editor and GDScript as "AnimalToad" or "NpcToad".
351
341
///
352
- /// # Hiding Classes
342
+ /// # Hiding classes
353
343
///
354
344
/// If you want to register a class with Godot, but not have it show up in the editor then you can use `#[class(hide)]`.
355
345
///
@@ -362,6 +352,35 @@ use crate::util::ident;
362
352
///
363
353
/// Even though this class is a `Node` and it has an init function, it still won't show up in the editor as a node you can add to a scene
364
354
/// because we have added a `hide` key to the class. This will also prevent it from showing up in documentation.
355
+ ///
356
+ /// # Fine-grained inference hints
357
+ ///
358
+ /// The derive macro is relatively smart about recognizing `Base<T>` and `OnReady<T>` types, and works also if those are qualified.
359
+ ///
360
+ /// However, there may be situations where you need to help it out -- for example, if you have a type alias for `Base<T>`, or use an unrelated
361
+ /// `my_module::Base<T>` with a different meaning.
362
+ ///
363
+ /// In this case, you can manually override the behavior with the `#[hint]` attribute. It takes multiple standalone keys:
364
+ /// - `base` and `no_base`
365
+ /// - `onready` and `no_onready`
366
+ ///
367
+ /// ```no_run
368
+ /// use godot::engine::Node;
369
+ ///
370
+ /// // There's no reason to do this, but for the sake of example:
371
+ /// type Super<T> = godot::obj::Base<T>;
372
+ /// type Base<T> = godot::obj::Gd<T>;
373
+ ///
374
+ /// #[derive(godot::register::GodotClass)]
375
+ /// #[class(base = Node)]
376
+ /// struct MyStruct {
377
+ /// #[hint(base)]
378
+ /// base: Super<Node>,
379
+ ///
380
+ /// #[hint(no_base)]
381
+ /// unbase: Base<Node>,
382
+ /// }
383
+ /// ```
365
384
#[ proc_macro_derive( GodotClass , attributes( class, base, hint, var, export, init, signal) ) ]
366
385
pub fn derive_godot_class ( input : TokenStream ) -> TokenStream {
367
386
translate ( input, class:: derive_godot_class)
@@ -486,7 +505,7 @@ pub fn derive_to_godot(input: TokenStream) -> TokenStream {
486
505
translate ( input, derive:: derive_to_godot)
487
506
}
488
507
489
- /// Derive macro for [`FromGodot`](../builtin/meta/trait.FromVariant .html) on structs or enums.
508
+ /// Derive macro for [`FromGodot`](../builtin/meta/trait.FromGodot .html) on structs or enums.
490
509
///
491
510
/// # Example
492
511
///
@@ -520,7 +539,7 @@ pub fn derive_from_godot(input: TokenStream) -> TokenStream {
520
539
translate ( input, derive:: derive_from_godot)
521
540
}
522
541
523
- /// Derive macro for [`Var`](../bind /property/trait.Var.html) on enums.
542
+ /// Derive macro for [`Var`](../register /property/trait.Var.html) on enums.
524
543
///
525
544
/// Currently has some tight requirements which are expected to be softened as implementation expands:
526
545
/// - Only works for enums, structs aren't supported by this derive macro at the moment.
@@ -560,7 +579,7 @@ pub fn derive_property(input: TokenStream) -> TokenStream {
560
579
translate ( input, derive:: derive_var)
561
580
}
562
581
563
- /// Derive macro for [`Export`](../bind /property/trait.Export.html) on enums.
582
+ /// Derive macro for [`Export`](../register /property/trait.Export.html) on enums.
564
583
///
565
584
/// Currently has some tight requirements which are expected to be softened as implementation expands, see requirements for [`Var`].
566
585
#[ proc_macro_derive( Export ) ]
0 commit comments