@@ -53,18 +53,29 @@ impl fmt::Display for PathElem {
53
53
}
54
54
55
55
#[ derive( Clone ) ]
56
- struct LinkedPathNode < ' a > {
56
+ pub struct LinkedPathNode < ' a > {
57
57
node : PathElem ,
58
58
next : LinkedPath < ' a > ,
59
59
}
60
60
61
- type LinkedPath < ' a > = Option < & ' a LinkedPathNode < ' a > > ;
61
+ #[ derive( Copy , Clone ) ]
62
+ pub struct LinkedPath < ' a > ( Option < & ' a LinkedPathNode < ' a > > ) ;
63
+
64
+ impl < ' a > LinkedPath < ' a > {
65
+ pub fn empty ( ) -> LinkedPath < ' a > {
66
+ LinkedPath ( None )
67
+ }
68
+
69
+ pub fn from ( node : & ' a LinkedPathNode ) -> LinkedPath < ' a > {
70
+ LinkedPath ( Some ( node) )
71
+ }
72
+ }
62
73
63
74
impl < ' a > Iterator for LinkedPath < ' a > {
64
75
type Item = PathElem ;
65
76
66
77
fn next ( & mut self ) -> Option < PathElem > {
67
- match * self {
78
+ match self . 0 {
68
79
Some ( node) => {
69
80
* self = node. next ;
70
81
Some ( node. node )
@@ -384,7 +395,7 @@ impl<'ast> Map<'ast> {
384
395
pub fn with_path < T , F > ( & self , id : NodeId , f : F ) -> T where
385
396
F : FnOnce ( PathElems ) -> T ,
386
397
{
387
- self . with_path_next ( id, None , f)
398
+ self . with_path_next ( id, LinkedPath :: empty ( ) , f)
388
399
}
389
400
390
401
pub fn path_to_string ( & self , id : NodeId ) -> String {
@@ -422,7 +433,7 @@ impl<'ast> Map<'ast> {
422
433
_ => f ( [ ] . iter ( ) . cloned ( ) . chain ( next) )
423
434
}
424
435
} else {
425
- self . with_path_next ( parent, Some ( & LinkedPathNode {
436
+ self . with_path_next ( parent, LinkedPath :: from ( & LinkedPathNode {
426
437
node : self . get_path_elem ( id) ,
427
438
next : next
428
439
} ) , f)
0 commit comments