@@ -48,6 +48,7 @@ pub struct Scope {
48
48
enum Item {
49
49
Module ( Module ) ,
50
50
Struct ( Struct ) ,
51
+ Function ( Function ) ,
51
52
Trait ( Trait ) ,
52
53
Enum ( Enum ) ,
53
54
Impl ( Impl ) ,
@@ -372,6 +373,22 @@ impl Scope {
372
373
self
373
374
}
374
375
376
+ /// Push a new function definition, returning a mutable reference to it.
377
+ pub fn new_fn ( & mut self , name : & str ) -> & mut Function {
378
+ self . push_fn ( Function :: new ( name) ) ;
379
+
380
+ match * self . items . last_mut ( ) . unwrap ( ) {
381
+ Item :: Function ( ref mut v) => v,
382
+ _ => unreachable ! ( ) ,
383
+ }
384
+ }
385
+
386
+ /// Push a function definition
387
+ pub fn push_fn ( & mut self , item : Function ) -> & mut Self {
388
+ self . items . push ( Item :: Function ( item) ) ;
389
+ self
390
+ }
391
+
375
392
/// Push a new trait definition, returning a mutable reference to it.
376
393
pub fn new_trait ( & mut self , name : & str ) -> & mut Trait {
377
394
self . push_trait ( Trait :: new ( name) ) ;
@@ -458,6 +475,7 @@ impl Scope {
458
475
match * item {
459
476
Item :: Module ( ref v) => v. fmt ( fmt) ?,
460
477
Item :: Struct ( ref v) => v. fmt ( fmt) ?,
478
+ Item :: Function ( ref v) => v. fmt ( false , fmt) ?,
461
479
Item :: Trait ( ref v) => v. fmt ( fmt) ?,
462
480
Item :: Enum ( ref v) => v. fmt ( fmt) ?,
463
481
Item :: Impl ( ref v) => v. fmt ( fmt) ?,
@@ -623,6 +641,17 @@ impl Module {
623
641
self
624
642
}
625
643
644
+ /// Push a new function definition, returning a mutable reference to it.
645
+ pub fn new_fn ( & mut self , name : & str ) -> & mut Function {
646
+ self . scope . new_fn ( name)
647
+ }
648
+
649
+ /// Push a function definition
650
+ pub fn push_fn ( & mut self , item : Function ) -> & mut Self {
651
+ self . scope . push_fn ( item) ;
652
+ self
653
+ }
654
+
626
655
/// Push a new enum definition, returning a mutable reference to it.
627
656
pub fn new_enum ( & mut self , name : & str ) -> & mut Enum {
628
657
self . scope . new_enum ( name)
@@ -1509,7 +1538,7 @@ impl Import {
1509
1538
}
1510
1539
}
1511
1540
1512
- // ===== impl Func =====
1541
+ // ===== impl Function =====
1513
1542
1514
1543
impl Function {
1515
1544
/// Return a new function definition.
0 commit comments