Improved for loop

This commit is contained in:
2026-05-07 23:43:22 +02:00
parent c7ada72029
commit 8b409f4ccf
4 changed files with 18 additions and 7 deletions
+13 -4
View File
@@ -541,12 +541,14 @@ impl ToRust for Statement {
}
Statement::For {
mutable,
pattern,
iterator,
body,
} => {
cg.add_indentedln(&format!(
"for {} in {}",
"for {}{} in {}",
get_mutable(*mutable),
pattern.get_rust(),
iterator.get_rust()
));
@@ -590,15 +592,18 @@ impl ToRust for FunctionDecl {
impl GetRust for VarDecl {
fn get_rust(&self) -> String {
let mutability = if self.mutable { "mut " } else { "" };
let ty = self
.type_
.as_ref()
.map(|t| format!(": {}", t.get_rust()))
.unwrap_or_default();
format!("{}{}{}", mutability, self.name.get_rust(), ty)
format!(
"{}{}{}",
get_mutable(self.mutable),
self.name.get_rust(),
ty
)
}
}
@@ -709,3 +714,7 @@ pub fn get_static_type_path(path: &Path) -> String {
pub fn get_type_postfixes(postfixes: &[TypePostfix]) -> String {
postfixes.iter().map(TypePostfix::get_rust).collect()
}
pub fn get_mutable(mutable: bool) -> String {
if mutable { "mut " } else { "" }.to_string()
}