From 03b75f75ab1e097c94601968f2c099b2ad085e9d Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:37:52 +0200 Subject: [PATCH] msggen: fix edge cases in rust composite field names --- contrib/msggen/msggen/gen/rpc/rust.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/msggen/msggen/gen/rpc/rust.py b/contrib/msggen/msggen/gen/rpc/rust.py index 6b3fb19f4265..6c947f34836d 100644 --- a/contrib/msggen/msggen/gen/rpc/rust.py +++ b/contrib/msggen/msggen/gen/rpc/rust.py @@ -212,8 +212,8 @@ def gen_primitive(p): def rename_if_necessary(original, name): - if original != name: - return f' #[serde(rename = "{original}")]\n' + if str(original) != str(name): + return f" #[serde(rename = \"{original}\")]\n" else: return f"" @@ -268,10 +268,11 @@ def gen_composite(c, meta) -> Tuple[str, str]: defi = "" if c.deprecated: defi += " #[deprecated]\n" + defi += rename_if_necessary(c.name, c.normalized()) if not c.optional: - defi += f" pub {c.name}: {c.typename},\n" + defi += f" pub {c.normalized()}: {c.typename},\n" else: - defi += f' #[serde(skip_serializing_if = "Option::is_none")]\n pub {c.name}: Option<{c.typename}>,\n' + defi += f" #[serde(skip_serializing_if = \"Option::is_none\")]\n pub {c.normalized()}: Option<{c.typename}>,\n" return defi, r