gdnative_core/object/
memory.rs

1//! Marker types to express the memory management method of Godot types.
2// Note: markers are enums to prevent instantiation and avoid derive (empty/non-inhabitable types)
3
4use crate::object::bounds::MemorySpec;
5
6/// Marker that indicates that a type is manually managed.
7pub enum ManuallyManaged {}
8
9/// Marker that indicates that a type is reference-counted.
10pub enum RefCounted {}
11
12/// Trait to parameterize over the memory management markers [`ManuallyManaged`] and [`RefCounted`].
13///
14/// This trait is sealed and has no public members.
15///
16/// It defines how memory is managed for Godot objects in smart pointers, for example [`Ref`][super::Ref].
17/// Generally, classes inheriting `Reference` are ref-counted, while the rest (i.e. everything inheriting
18/// `Object` which is not a `Reference`) is manually managed.
19pub trait Memory: MemorySpec + private::Sealed {}
20
21impl Memory for ManuallyManaged {}
22impl private::Sealed for ManuallyManaged {}
23
24impl Memory for RefCounted {}
25impl private::Sealed for RefCounted {}
26
27mod private {
28    pub trait Sealed {}
29}