Skip to content

Commit

Permalink
Rust: Add interface doc comments.
Browse files Browse the repository at this point in the history
Add interface documentation as doc comments for the generated Rust modules.
  • Loading branch information
sunfishcode committed Nov 18, 2024
1 parent 0640625 commit eac30fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,13 @@ macro_rules! {macro_name} {{
(snake, module_path)
}

pub fn finish_append_submodule(mut self, snake: &str, module_path: Vec<String>) {
pub fn finish_append_submodule(mut self, snake: &str, module_path: Vec<String>, docs: &Docs) {
let module = self.finish();

self.rustdoc(docs);
let docs = mem::take(&mut self.src).to_string();
let docs = docs.trim_end();

let path_to_root = self.path_to_root();
let used_static = if self.gen.opts.disable_custom_section_link_helpers {
String::new()
Expand All @@ -439,6 +444,7 @@ macro_rules! {macro_name} {{
};
let module = format!(
"\
{docs}
pub mod {snake} {{
{used_static}
{module}
Expand Down
9 changes: 7 additions & 2 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,9 @@ impl WorldGenerator for RustWasm {

gen.generate_imports(resolve.interfaces[id].functions.values());

gen.finish_append_submodule(&snake, module_path);
let docs = &resolve.interfaces[id].docs;

gen.finish_append_submodule(&snake, module_path, docs);

Ok(())
}
Expand Down Expand Up @@ -1022,7 +1024,10 @@ impl WorldGenerator for RustWasm {
gen.types(id);
let macro_name =
gen.generate_exports(Some((id, name)), resolve.interfaces[id].functions.values())?;
gen.finish_append_submodule(&snake, module_path);

let docs = &resolve.interfaces[id].docs;

gen.finish_append_submodule(&snake, module_path, docs);
self.export_macros
.push((macro_name, self.interface_names[&id].path.clone()));

Expand Down

0 comments on commit eac30fe

Please sign in to comment.