You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: godot-core/src/obj/dyn_gd.rs
+29-18Lines changed: 29 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ use std::{fmt, ops};
46
46
/// #[derive(GodotClass)]
47
47
/// #[class(init)]
48
48
/// struct Monster {
49
-
/// #[init(val = 100)]
49
+
/// #[init(val = 100)]
50
50
/// hitpoints: u16,
51
51
/// }
52
52
///
@@ -137,24 +137,39 @@ use std::{fmt, ops};
137
137
/// and it can query the dynamic type of the object. Based on that type, it can find the `impl Health` implementation matching the correct class.
138
138
/// Behind the scenes, everything is wired up correctly so that you can restore the original `DynGd` even after it has passed through Godot.
139
139
///
140
-
/// # `#[export]` for `DynGd<T, D>`
140
+
/// # Exporting
141
141
///
142
-
/// Exporting `DynGd<T, D>` is possible only via [`OnEditor`] or [`Option`].
142
+
/// [Like `Gd<T>`](struct.Gd.html#exporting), using `#[export]` with `DynGd<T, D>` is possible only via [`OnEditor`] or [`Option`].
143
143
/// `DynGd<T, D>` can also be exported directly as an element of an array such as `Array<DynGd<T, D>>`.
144
144
///
145
-
/// Since `DynGd<T, D>` represents shared functionality `D` across classes inheriting from `T`,
146
-
/// consider using `#[export] Gd<T>` instead of `#[export] DynGd<T, D>`
147
-
/// in cases when `T` is a concrete Rust `GodotClass`.
145
+
/// When talking about "exporting", the following paragraphs assume that you wrap `DynGd` in one of those types.
148
146
///
149
-
/// ## Node based classes
147
+
/// In cases where `T: AsDyn<D>` (the trait is directly implemented on the user class, i.e. no upcasting), exporting `DynGd<T, D>` is
148
+
/// equivalent to exporting `Gd<T>` regarding Inspector UI.
150
149
///
151
-
/// `#[export]` for a `DynGd<T, D>` works identically to `#[export]` `Gd<T>` for `T` inheriting Node classes.
152
-
/// Godot will report an error if the conversion fails, but it will only do so when accessing the given value.
150
+
/// ## Node-based classes
153
151
///
154
-
/// ## Resource based classes
152
+
/// If `T` inherits `Node`, exporting `DynGd<T, D>` works identically to `Gd<T>`.
155
153
///
156
-
/// `#[export]` for a `DynGd<T, D>` allows you to limit the available choices to implementors of a given trait `D` whose base inherits the specified `T`
157
-
/// (for example, `#[export] Option<DynGd<Resource, dyn MyTrait>>` won't include Rust classes with an Object base, even if they implement `MyTrait`).
154
+
/// If you try to assign a class from the editor that does not implement trait `D`, Godot will report a conversion-failed error,
155
+
/// but it will only do so when accessing the given value.
156
+
///
157
+
/// ## Resource-based classes
158
+
///
159
+
/// If `T` inherits `Resource`, exporting `DynGd<T, D>>` will limit the available choices to known implementors of the trait `D`.
160
+
///
161
+
/// For example, let's say you have four Rust classes:
0 commit comments