Type params gen
This commit is contained in:
+2
-1
@@ -13,7 +13,8 @@ pub struct Block(pub Vec<Statement>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TypeExpr {
|
||||
Path(StaticPath, Vec<TypeExpr>),
|
||||
Path(StaticPath),
|
||||
PathParams(StaticPath, Vec<TypeExpr>),
|
||||
Tuple(Vec<TypeExpr>),
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -33,8 +33,14 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
|
||||
Rule::tuple_type => TypeExpr::Tuple(pair.into_inner().map(TypeExpr::from).collect()),
|
||||
Rule::path_type => {
|
||||
let mut inner = pair.into_inner();
|
||||
let path = StaticPath::from(inner.next().unwrap());
|
||||
let params = inner.map(TypeExpr::from).collect::<Vec<_>>();
|
||||
|
||||
TypeExpr::Path(StaticPath::from(inner.next().unwrap()), inner.map(TypeExpr::from).collect())
|
||||
if params.len() == 0 {
|
||||
TypeExpr::Path(path)
|
||||
} else {
|
||||
TypeExpr::PathParams(path, params)
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("{pair:#?}"),
|
||||
}
|
||||
|
||||
@@ -76,6 +76,17 @@ impl GetRust for TypeExpr {
|
||||
fn get_rust(&self) -> String {
|
||||
match self {
|
||||
TypeExpr::Path(path) => get_static_type_path(path),
|
||||
TypeExpr::PathParams(path, params) => {
|
||||
format!(
|
||||
"{}<{}>",
|
||||
get_static_type_path(path),
|
||||
params
|
||||
.iter()
|
||||
.map(|t| t.get_rust())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
TypeExpr::Tuple(types) => format!(
|
||||
"({})",
|
||||
types
|
||||
|
||||
Reference in New Issue
Block a user