Fixed class lifetimes

This commit is contained in:
2026-05-10 04:01:54 +02:00
parent e6c030e8c8
commit 5916daaada
8 changed files with 47 additions and 29 deletions
-5
View File
@@ -1,5 +0,0 @@
mod app;
mod task;
mod plugin;
mod logger;
mod event;
+6 -2
View File
@@ -1,6 +1,10 @@
mod core;
mod app;
mod task;
mod plugin;
mod logger;
mod event;
use <core::app>;
use <app>;
// use <plugins::greeting>;
// use <plugins::statistics>;
+31 -12
View File
@@ -1,7 +1,7 @@
use parser::ast::{
Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generics, Identifier, Literal,
Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind, TypeExpr,
TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility,
Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generic, Generics, Identifier,
Literal, Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind,
TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility,
};
// ---------------------------------------------------------------------------
@@ -383,7 +383,20 @@ impl ToRust for TopLevelKind {
cg.addln("}\n");
// Constructor
cg.addln(&format!("impl {} {{", name.get_rust()));
cg.addln(&format!(
"impl{} {}{} {{",
generics.get_rust(),
name.get_rust(),
format!(
"<{}>",
generics
.0
.iter()
.map(|v| (false, v).get_rust())
.collect::<Vec<_>>()
.join(", ")
)
));
cg.indent += 1;
let params_str = constructor
@@ -725,11 +738,21 @@ impl GetRust for Generics {
"<{}>",
self.0
.iter()
.map(|generic| match generic {
parser::ast::Generic::Lifetime(name) => format!("'{}", name.get_rust()),
parser::ast::Generic::Type(name, requirements) => {
.map(|v| (true, v).get_rust())
.collect::<Vec<_>>()
.join(", ")
)
}
}
}
impl GetRust for (bool, &Generic) {
fn get_rust(&self) -> String {
match &self.1 {
Generic::Lifetime(name) => format!("'{}", name.get_rust()),
Generic::Type(name, requirements) => {
name.get_rust()
+ &(if requirements.len() == 0 {
+ &(if !self.0 && requirements.len() == 0 {
String::new()
} else {
format!(
@@ -742,10 +765,6 @@ impl GetRust for Generics {
)
})
}
})
.collect::<Vec<_>>()
.join(", ")
)
}
}
}