mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
cln-rpc: Generate ToString for Enums
This will return the stringified name of the variant.
This commit is contained in:
parent
32f9d78096
commit
557cd183ac
BIN
cln-rpc/src/model.rs
generated
BIN
cln-rpc/src/model.rs
generated
Binary file not shown.
@ -111,6 +111,24 @@ def gen_enum(e):
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
|
||||
""")
|
||||
|
||||
# Implement ToString for enums so we can print them nicely as they
|
||||
# appear in the schemas.
|
||||
decl += dedent(f"""\
|
||||
impl ToString for {e.typename} {{
|
||||
fn to_string(&self) -> String {{
|
||||
match self {{
|
||||
""")
|
||||
for v in e.variants:
|
||||
norm = v.normalized()
|
||||
decl += f" {e.typename}::{norm} => \"{norm}\",\n"
|
||||
decl += dedent(f"""\
|
||||
}}.to_string()
|
||||
}}
|
||||
}}
|
||||
|
||||
""")
|
||||
|
||||
typename = e.typename
|
||||
@ -124,7 +142,7 @@ def gen_enum(e):
|
||||
defi += rename_if_necessary(str(e.name), e.name.normalized())
|
||||
defi += f" pub {e.name.normalized()}: {typename},\n"
|
||||
else:
|
||||
defi = f' #[serde(skip_serializing_if = "Option::is_none")]\n'
|
||||
defi = f" #[serde(skip_serializing_if = \"Option::is_none\")]\n"
|
||||
defi += f" pub {e.name.normalized()}: Option<{typename}>,\n"
|
||||
|
||||
return defi, decl
|
||||
|
Loading…
Reference in New Issue
Block a user