Refrence lifetimes

This commit is contained in:
2026-05-10 00:35:14 +02:00
parent 910657c755
commit 3e25bf0456
4 changed files with 21 additions and 5 deletions
+2
View File
@@ -16,6 +16,8 @@ pub struct Block(pub Vec<Statement>);
pub enum TypePostfix {
Ref,
RefMut,
RefLifetime(Identifier),
RefMutLifetime(Identifier),
}
#[derive(Debug, Clone, Serialize)]
+1 -1
View File
@@ -71,7 +71,7 @@ path_type = {
}
ref_type = {
mutable? ~ "*"
mutable? ~ lifetime? ~ "*"
}
type_expr = {
+16 -4
View File
@@ -49,14 +49,26 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
let rule = pair.as_rule();
let inner = pair.into_inner();
let mut inner = pair.into_inner();
match rule {
Rule::ref_type => {
if inner.peek().is_some() {
TypePostfix::RefMut
let mutable = listen_rule(&mut inner, Rule::mutable);
let lifetime = consume_rule(&mut inner, Rule::lifetime)
.map(|pair| Identifier::from(pair.into_inner().next().unwrap()));
if mutable {
if let Some(lifetime) = lifetime {
TypePostfix::RefMutLifetime(lifetime)
} else {
TypePostfix::Ref
}
} else {
TypePostfix::Ref
if let Some(lifetime) = lifetime {
TypePostfix::RefLifetime(lifetime)
} else {
TypePostfix::RefMut
}
}
}
_ => unimplemented!("{rule:#?}"),
+2
View File
@@ -634,6 +634,8 @@ impl GetRust for TypePostfix {
match self {
TypePostfix::Ref => format!("&"),
TypePostfix::RefMut => format!("&mut "),
TypePostfix::RefLifetime(lifetime) => format!("&'{} ", lifetime.get_rust()),
TypePostfix::RefMutLifetime(lifetime) => format!("&'{} mut ", lifetime.get_rust()),
}
}
}