@@ -12,43 +12,56 @@ pub fn class_doc_link(class: &GodotClass) -> String {
12
12
13
13
pub fn official_doc_url ( class : & GodotClass ) -> String {
14
14
format ! (
15
- "https://godot.readthedocs.io/en/latest /classes/class_{lower_case}.html" ,
15
+ "https://godot.readthedocs.io/en/stable /classes/class_{lower_case}.html" ,
16
16
lower_case = class. name. to_lowercase( ) ,
17
17
)
18
18
}
19
19
20
+ pub fn generate_module_doc ( class : & GodotClass ) -> TokenStream {
21
+ let module_doc = format ! (
22
+ "This module contains types related to the API class [`{m}`][super::{m}]." ,
23
+ m = class. name
24
+ ) ;
25
+
26
+ quote ! {
27
+ #![ doc=#module_doc]
28
+ }
29
+ }
30
+
20
31
pub fn generate_class_documentation ( api : & Api , class : & GodotClass ) -> TokenStream {
21
32
let has_parent = !class. base_class . is_empty ( ) ;
22
33
let singleton_str = if class. singleton { "singleton " } else { "" } ;
23
- let ownership_type = if class. is_refcounted ( ) {
24
- "reference counted"
34
+ let memory_type = if class. is_refcounted ( ) {
35
+ "reference- counted"
25
36
} else {
26
- "unsafe "
37
+ "manually managed "
27
38
} ;
28
39
29
- let summary_doc = if & class. name == "Reference" {
40
+ let mut summary_doc = if & class. name == "Reference" {
30
41
"Base class of all reference-counted types. Inherits `Object`." . into ( )
31
42
} else if & class. name == "Object" {
32
- "The base class of most Godot classes ." . into ( )
43
+ "The base class of all classes in the Godot hierarchy ." . into ( )
33
44
} else if has_parent {
34
45
format ! (
35
- "`{api_type} {singleton}class {name}` inherits `{base_class}` ({ownership_type })." ,
46
+ "`{api_type} {singleton}class {name}` inherits `{base_class}` ({memory_type })." ,
36
47
api_type = class. api_type,
37
48
name = class. name,
38
49
base_class = class. base_class,
39
- ownership_type = ownership_type ,
40
- singleton = singleton_str
50
+ memory_type = memory_type ,
51
+ singleton = singleton_str,
41
52
)
42
53
} else {
43
54
format ! (
44
- "`{api_type} {singleton}class {name}` ({ownership_type}). " ,
55
+ "`{api_type} {singleton}class {name}` ({memory_type}) " ,
45
56
api_type = class. api_type,
46
57
name = class. name,
47
- ownership_type = ownership_type ,
58
+ memory_type = memory_type ,
48
59
singleton = singleton_str,
49
60
)
50
61
} ;
51
62
63
+ append_related_module ( & mut summary_doc, class) ;
64
+
52
65
let official_docs = format ! (
53
66
r#"## Official documentation
54
67
@@ -66,7 +79,7 @@ The lifetime of this object is automatically managed through reference counting.
66
79
format ! (
67
80
r#"## Memory management
68
81
69
- Non reference counted objects such as the ones of this type are usually owned by the engine.
82
+ Non- reference- counted objects, such as the ones of this type, are usually owned by the engine.
70
83
71
84
`{name}` is a reference-only type. Persistent references can
72
85
only exist in the unsafe `Ref<{name}>` form.
@@ -113,7 +126,7 @@ This class is used to interact with Godot's editor."#
113
126
let safety_doc = r#"
114
127
## Safety
115
128
116
- All types in the Godot API have "interior mutability" in Rust parlance.
129
+ All types in the Godot API have _interior mutability_ in Rust parlance.
117
130
To enforce that the official [thread-safety guidelines][thread-safety] are
118
131
followed, the typestate pattern is used in the `Ref` and `TRef` smart pointers,
119
132
and the `Instance` API. The typestate `Access` in these types tracks whether the
@@ -145,3 +158,16 @@ fn list_base_classes(output: &mut impl Write, api: &Api, parent_name: &str) -> G
145
158
146
159
Ok ( ( ) )
147
160
}
161
+
162
+ // If present, links to the module with related (C++: nested) types.
163
+ fn append_related_module ( string : & mut String , class : & GodotClass ) {
164
+ use std:: fmt:: Write ;
165
+ if class. has_related_module ( ) {
166
+ write ! (
167
+ string,
168
+ "\n \n This class has related types in the [`{m}`][super::{m}] module." ,
169
+ m = class. module( )
170
+ )
171
+ . expect ( "append to string via write!" ) ;
172
+ }
173
+ }
0 commit comments