Generate Rust enum definitions from a Python dictionary. Args: d (list): The list containing the enum variants. enum_name (str): The name of the enum to generate. derives (str): The derive attributes to include. strip_prefix (str, optional): A prefix to strip fro
(d, enum_name, derives, strip_prefix="")
| 34 | |
| 35 | |
| 36 | def dump_enum(d, enum_name, derives, strip_prefix=""): |
| 37 | """Generate Rust enum definitions from a Python dictionary. |
| 38 | |
| 39 | Args: |
| 40 | d (list): The list containing the enum variants. |
| 41 | enum_name (str): The name of the enum to generate. |
| 42 | derives (str): The derive attributes to include. |
| 43 | strip_prefix (str, optional): A prefix to strip from the variant names. Defaults to "". |
| 44 | |
| 45 | Returns: |
| 46 | list: A list of strings representing the enum definition. |
| 47 | """ |
| 48 | items = sorted(d) |
| 49 | print(f"items is {items}") |
| 50 | content = [f"{derives}\n"] |
| 51 | content.append("#[repr(u32)]\n") |
| 52 | content.append("#[allow(non_camel_case_types, clippy::upper_case_acronyms)]\n") |
| 53 | content.append(f"pub enum {enum_name} {{\n") |
| 54 | for i, item in enumerate(items): |
| 55 | name = str(item).removeprefix(strip_prefix) |
| 56 | content.append(f" {name} = {i},\n") |
| 57 | content.append("}\n\n") |
| 58 | return content |
| 59 | |
| 60 | |
| 61 | def dump_bitflags(d, prefix, derives, struct_name, int_t): |