MCPcopy Index your code
hub / github.com/RustPython/RustPython / dump_enum

Function dump_enum

scripts/generate_sre_constants.py:36–58  ·  view source on GitHub ↗

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="")

Source from the content-addressed store, hash-verified

34
35
36def 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
61def dump_bitflags(d, prefix, derives, struct_name, int_t):

Callers 1

mainFunction · 0.85

Calls 6

sortedFunction · 0.85
enumerateFunction · 0.85
strFunction · 0.85
printFunction · 0.50
appendMethod · 0.45
removeprefixMethod · 0.45

Tested by

no test coverage detected