|
7 | 7 |
|
8 | 8 | //! Different ways how bounds of a `GodotClass` can be checked.
|
9 | 9 | //!
|
10 |
| -//! This module contains three traits that can be used to check the characteristics of a `GodotClass` type: |
| 10 | +//! This module contains multiple traits that can be used to check the characteristics of a `GodotClass` type: |
11 | 11 | //!
|
12 | 12 | //! 1. [`Declarer`] tells you whether the class is provided by the engine or user-defined.
|
13 | 13 | //! - [`DeclEngine`] is used for all classes provided by the engine (e.g. `Node3D`).
|
|
19 | 19 | //! - [`MemRefCounted`] is used for `RefCounted` classes and derived.
|
20 | 20 | //! - [`MemManual`] is used for `Object` and all inherited classes, which are not `RefCounted` (e.g. `Node`).<br><br>
|
21 | 21 | //!
|
22 |
| -//! 3. [`DynMemory`] is used to check the memory strategy of the **dynamic** type. |
23 |
| -//! |
24 |
| -//! When you operate on methods of `T` or `Gd<T>` and are interested in instances, you can use this. |
25 |
| -//! Most of the time, this is not what you want -- just use `Memory` if you want to know if a type is manually managed or ref-counted. |
26 |
| -//! - [`MemRefCounted`] is used for `RefCounted` classes and derived. These are **always** reference-counted. |
27 |
| -//! - [`MemManual`] is used instances inheriting `Object`, which are not `RefCounted` (e.g. `Node`). Excludes `Object` itself. These are |
28 |
| -//! **always** manually managed. |
29 |
| -//! - [`MemDynamic`] is used for `Object` instances. `Gd<Object>` can point to objects of any possible class, so whether we are dealing with |
30 |
| -//! a ref-counted or manually-managed object is determined only at runtime. |
| 22 | +// FIXME excluded because broken; see below. |
| 23 | +// 3. [`DynMemory`] is used to check the memory strategy of the **dynamic** type. |
| 24 | +// |
| 25 | +// When you operate on methods of `T` or `Gd<T>` and are interested in instances, you can use this. |
| 26 | +// Most of the time, this is not what you want -- just use `Memory` if you want to know if a type is manually managed or ref-counted. |
| 27 | +// - [`MemRefCounted`] is used for `RefCounted` classes and derived. These are **always** reference-counted. |
| 28 | +// - [`MemManual`] is used instances inheriting `Object`, which are not `RefCounted` (e.g. `Node`). Excludes `Object` itself. These are |
| 29 | +// **always** manually managed. |
| 30 | +// - [`MemDynamic`] is used for `Object` instances. `Gd<Object>` can point to objects of any possible class, so whether we are dealing with |
| 31 | +// a ref-counted or manually-managed object is determined only at runtime. |
31 | 32 | //!
|
32 | 33 | //!
|
33 | 34 | //! # Example
|
|
44 | 45 | //! }
|
45 | 46 | //! ```
|
46 | 47 | //!
|
47 |
| -//! Note that depending on if you want to exclude `Object`, you should use `DynMemory` instead of `Memory`. |
| 48 | +// Note that depending on if you want to exclude `Object`, you should use `DynMemory` instead of `Memory`. |
48 | 49 |
|
49 | 50 | use crate::obj::cap::GodotDefault;
|
50 | 51 | use crate::obj::{Bounds, Gd, GodotClass, RawGd};
|
@@ -86,6 +87,10 @@ pub(super) mod private {
|
86 | 87 | /// Defines the memory strategy of the static type.
|
87 | 88 | type Memory: Memory;
|
88 | 89 |
|
| 90 | + // FIXME: this is broken as a bound: one cannot use T: Bounds<DynMemory = MemRefCounted> to include Object AND RefCounted, |
| 91 | + // since Object itself has DynMemory = MemDynamic. Needs to either use traits like in gdnative, or more types to account for |
| 92 | + // different combinations (as only positive ones can be expressed, not T: Bounds<Memory != MemManual>). |
| 93 | + #[doc(hidden)] |
89 | 94 | /// Defines the memory strategy of the instance (at runtime).
|
90 | 95 | type DynMemory: DynMemory;
|
91 | 96 |
|
@@ -146,6 +151,7 @@ pub trait Memory: Sealed {}
|
146 | 151 | /// Specifies the memory strategy of the dynamic type.
|
147 | 152 | ///
|
148 | 153 | /// For `Gd<Object>`, it is determined at runtime whether the instance is manually managed or ref-counted.
|
| 154 | +#[doc(hidden)] |
149 | 155 | pub trait DynMemory: Sealed {
|
150 | 156 | /// Initialize reference counter
|
151 | 157 | #[doc(hidden)]
|
@@ -254,6 +260,7 @@ impl DynMemory for MemRefCounted {
|
254 | 260 |
|
255 | 261 | /// Memory managed through Godot reference counter, if present; otherwise manual.
|
256 | 262 | /// This is used only for `Object` classes.
|
| 263 | +#[doc(hidden)] |
257 | 264 | pub struct MemDynamic {}
|
258 | 265 | impl MemDynamic {
|
259 | 266 | /// Check whether dynamic type is ref-counted.
|
|
0 commit comments