Skip to content

Commit

Permalink
Generate docs for bitfields
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Aug 14, 2024
1 parent fbe85ea commit cbe3749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
25 changes: 6 additions & 19 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,39 +467,26 @@ fn write_enums(interface: &Interface) -> Vec<TokenStream> {

let name = make_ident(format!("{prefix}{}", entry.name.to_upper_camel_case()));

// if let Some(summary) = &entry.summary {
// for line in summary.lines() {
// let doc = line.trim();

// let mut c = doc.chars();
// let doc = c.next().unwrap().to_uppercase().collect::<String>()
// + c.as_str();

// writeln!(&mut variants, r##"#[doc = r#"{doc}"#]"##,)?;
// }
// }

// variants.push_str(&format!(
// "const {prefix}{name} = {value};",
// name = entry.name.to_upper_camel_case(),
// value = entry.value
// ))
let docs = description_to_docs(entry.summary.as_ref());

let value: u32 = if let Some(s) = entry.value.strip_prefix("0x") {
u32::from_str_radix(s, 16).expect("Invalid enum value")
} else {
entry.value.parse().expect("Invalid enum value")
};

variants.push(quote! { const #name = #value });
variants.push(quote! {
#(#docs)*
const #name = #value;
});
}

enums.push(quote! {
bitflags::bitflags! {
#(#docs)*
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub struct #name: u32 {
#(#variants);*
#(#variants)*
}
}

Expand Down
Loading

0 comments on commit cbe3749

Please sign in to comment.