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::greeting>;
// use <plugins::statistics>; // use <plugins::statistics>;
+41 -22
View File
@@ -1,7 +1,7 @@
use parser::ast::{ use parser::ast::{
Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generics, Identifier, Literal, Attribute, BinaryOp, Block, EnumItem, Expression, FunctionDecl, Generic, Generics, Identifier,
Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind, TypeExpr, Literal, Path, Pattern, Postfix, Prefix, Statement, StatementBranch, TopLevel, TopLevelKind,
TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility, TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, Visibility,
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -383,7 +383,20 @@ impl ToRust for TopLevelKind {
cg.addln("}\n"); cg.addln("}\n");
// Constructor // 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; cg.indent += 1;
let params_str = constructor let params_str = constructor
@@ -725,24 +738,7 @@ impl GetRust for Generics {
"<{}>", "<{}>",
self.0 self.0
.iter() .iter()
.map(|generic| match generic { .map(|v| (true, v).get_rust())
parser::ast::Generic::Lifetime(name) => format!("'{}", name.get_rust()),
parser::ast::Generic::Type(name, requirements) => {
name.get_rust()
+ &(if requirements.len() == 0 {
String::new()
} else {
format!(
": {}",
requirements
.iter()
.map(TypeExpr::get_rust)
.collect::<Vec<_>>()
.join("+")
)
})
}
})
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
) )
@@ -750,6 +746,29 @@ impl GetRust for Generics {
} }
} }
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 !self.0 && requirements.len() == 0 {
String::new()
} else {
format!(
": {}",
requirements
.iter()
.map(TypeExpr::get_rust)
.collect::<Vec<_>>()
.join("+")
)
})
}
}
}
}
pub fn get_static_type_path(path: &Path) -> String { pub fn get_static_type_path(path: &Path) -> String {
let rust_path = path.get_rust(); let rust_path = path.get_rust();