@@ -12,43 +12,56 @@ pub fn class_doc_link(class: &GodotClass) -> String {
1212
1313pub fn official_doc_url ( class : & GodotClass ) -> String {
1414 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" ,
1616 lower_case = class. name. to_lowercase( ) ,
1717 )
1818}
1919
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+
2031pub fn generate_class_documentation ( api : & Api , class : & GodotClass ) -> TokenStream {
2132 let has_parent = !class. base_class . is_empty ( ) ;
2233 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"
2536 } else {
26- "unsafe "
37+ "manually managed "
2738 } ;
2839
29- let summary_doc = if & class. name == "Reference" {
40+ let mut summary_doc = if & class. name == "Reference" {
3041 "Base class of all reference-counted types. Inherits `Object`." . into ( )
3142 } 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 ( )
3344 } else if has_parent {
3445 format ! (
35- "`{api_type} {singleton}class {name}` inherits `{base_class}` ({ownership_type })." ,
46+ "`{api_type} {singleton}class {name}` inherits `{base_class}` ({memory_type })." ,
3647 api_type = class. api_type,
3748 name = class. name,
3849 base_class = class. base_class,
39- ownership_type = ownership_type ,
40- singleton = singleton_str
50+ memory_type = memory_type ,
51+ singleton = singleton_str,
4152 )
4253 } else {
4354 format ! (
44- "`{api_type} {singleton}class {name}` ({ownership_type}). " ,
55+ "`{api_type} {singleton}class {name}` ({memory_type}) " ,
4556 api_type = class. api_type,
4657 name = class. name,
47- ownership_type = ownership_type ,
58+ memory_type = memory_type ,
4859 singleton = singleton_str,
4960 )
5061 } ;
5162
63+ append_related_module ( & mut summary_doc, class) ;
64+
5265 let official_docs = format ! (
5366 r#"## Official documentation
5467
@@ -66,7 +79,7 @@ The lifetime of this object is automatically managed through reference counting.
6679 format ! (
6780 r#"## Memory management
6881
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.
7083
7184`{name}` is a reference-only type. Persistent references can
7285only exist in the unsafe `Ref<{name}>` form.
@@ -113,7 +126,7 @@ This class is used to interact with Godot's editor."#
113126 let safety_doc = r#"
114127## Safety
115128
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.
117130To enforce that the official [thread-safety guidelines][thread-safety] are
118131followed, the typestate pattern is used in the `Ref` and `TRef` smart pointers,
119132and 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
145158
146159 Ok ( ( ) )
147160}
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