Constructor generics
This commit is contained in:
@@ -120,6 +120,7 @@ pub enum EnumItem {
|
|||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct ClassConstructor {
|
pub struct ClassConstructor {
|
||||||
pub visibility: Visibility,
|
pub visibility: Visibility,
|
||||||
|
pub generics: Generics,
|
||||||
pub params: ParamList,
|
pub params: ParamList,
|
||||||
pub body: Block,
|
pub body: Block,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ enum_decl = {
|
|||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
class_constructor = {
|
class_constructor = {
|
||||||
export? ~ "constructor" ~ "(" ~ param_list? ~ ")" ~ block
|
export? ~ "constructor" ~ generics? ~ "(" ~ param_list? ~ ")" ~ block
|
||||||
}
|
}
|
||||||
|
|
||||||
class_fields = {
|
class_fields = {
|
||||||
|
|||||||
@@ -211,12 +211,17 @@ impl From<pest::iterators::Pair<'_, Rule>> for ClassConstructor {
|
|||||||
|
|
||||||
let visibility = Visibility::from(&mut inner);
|
let visibility = Visibility::from(&mut inner);
|
||||||
|
|
||||||
|
let generics = consume_rule(&mut inner, Rule::generics)
|
||||||
|
.map(Generics::from)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let params = consume_rule(&mut inner, Rule::param_list)
|
let params = consume_rule(&mut inner, Rule::param_list)
|
||||||
.map(ParamList::from)
|
.map(ParamList::from)
|
||||||
.unwrap_or_else(|| ParamList(Vec::new()));
|
.unwrap_or_else(|| ParamList(Vec::new()));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
visibility,
|
visibility,
|
||||||
|
generics,
|
||||||
params,
|
params,
|
||||||
body: Block::from(inner.next().unwrap()),
|
body: Block::from(inner.next().unwrap()),
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -394,8 +394,9 @@ impl ToRust for TopLevelKind {
|
|||||||
.join(", ");
|
.join(", ");
|
||||||
|
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"{}fn new({}) -> Self {{",
|
"{}fn new{}({}) -> Self {{",
|
||||||
constructor.visibility.get_rust(),
|
constructor.visibility.get_rust(),
|
||||||
|
constructor.generics.get_rust(),
|
||||||
params_str
|
params_str
|
||||||
));
|
));
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
@@ -430,8 +431,9 @@ impl ToRust for TopLevelKind {
|
|||||||
|
|
||||||
// Constructor function
|
// Constructor function
|
||||||
cg.add_indentedln(&format!(
|
cg.add_indentedln(&format!(
|
||||||
"{}fn construct_class(&mut self, {}) {{",
|
"{}fn construct_class{}(&mut self, {}) {{",
|
||||||
constructor.visibility.get_rust(),
|
constructor.visibility.get_rust(),
|
||||||
|
constructor.generics.get_rust(),
|
||||||
params_str
|
params_str
|
||||||
));
|
));
|
||||||
cg.indent += 1;
|
cg.indent += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user