Function types

This commit is contained in:
2026-06-28 05:45:13 +02:00
parent 3ddb1bc601
commit 76541040c9
6 changed files with 104 additions and 2 deletions
+30 -1
View File
@@ -239,7 +239,6 @@ impl GetRust for TypeExpr {
Self::UnsafePtr { mutable, ty } => {
let mutable = if *mutable { "mut " } else { "const " };
format!("*{mutable}{}", ty.get_rust())
}
Self::Ref {
@@ -262,10 +261,40 @@ impl GetRust for TypeExpr {
Self::Dyn(ty) => {
format!("dyn {}", ty.get_rust())
}
Self::Fn {
kind,
return_type,
params,
} => {
format!(
"{} -> {}({})",
kind.get_rust(),
return_type.get_rust(),
params
.iter()
.map(TypeExpr::get_rust)
.collect::<Vec<_>>()
.join(", ")
)
}
}
}
}
impl GetRust for FnKind {
fn get_rust(&self) -> String {
match self {
Self::Fn => "fn",
Self::UnsafeFn => "unsafe fn",
Self::FnClosure => "Fn",
Self::FnMut => "FnMut",
Self::FnOnce => "FnOnce",
}
.to_string()
}
}
impl GenRust for Pattern {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
match self {