Var decl with repeat

This commit is contained in:
2026-07-04 09:55:23 +02:00
parent eeac773c06
commit 517a2e5a2b
5 changed files with 62 additions and 11 deletions
+29 -8
View File
@@ -188,14 +188,35 @@ impl GenRust for Statement {
impl GenRust for VarDecl {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
self.name.gen_rust(ctx, cg);
if self.tuple_names.is_empty() {
self.name.gen_rust(ctx, cg);
cg.add(
&self
.type_
.as_ref()
.map(|t| format!(": {}", t.get_rust()))
.unwrap_or_default(),
);
} else {
cg.add("(");
self.name.gen_rust(ctx, cg);
for name in &self.tuple_names {
cg.add(", ");
cg.add(
&self
.type_
.as_ref()
.map(|t| format!(": {}", t.get_rust()))
.unwrap_or_default(),
);
name.gen_rust(ctx, cg);
}
cg.add(")");
cg.add(
&self
.type_
.as_ref()
.map(|t| {
let t = vec![t.get_rust(); self.tuple_names.len() + 1];
format!(": ({})", t.join(", "))
})
.unwrap_or_default(),
);
}
}
}