File tree 2 files changed +28
-15
lines changed
2 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -791,19 +791,12 @@ impl Comment {
791
791
}
792
792
}
793
793
794
- /// Get the number of children this comment node has.
795
- pub fn num_children ( & self ) -> c_uint {
796
- unsafe {
797
- clang_Comment_getNumChildren ( self . x )
798
- }
799
- }
800
-
801
- /// Get this comment's `idx`th child comment
802
- pub fn get_child ( & self , idx : c_uint ) -> Option < Comment > {
803
- if idx >= self . num_children ( ) {
804
- None
805
- } else {
806
- Some ( Comment { x : unsafe { clang_Comment_getChild ( self . x , idx) } } )
794
+ /// Get this comment's children comment
795
+ pub fn get_children ( & self ) -> CommentChildrenIterator {
796
+ CommentChildrenIterator {
797
+ parent : self . x ,
798
+ length : unsafe { clang_Comment_getNumChildren ( self . x ) } ,
799
+ index : 0
807
800
}
808
801
}
809
802
@@ -840,6 +833,26 @@ impl Comment {
840
833
}
841
834
}
842
835
836
+ /// An iterator for a comment's children
837
+ pub struct CommentChildrenIterator {
838
+ parent : CXComment ,
839
+ length : c_uint ,
840
+ index : c_uint
841
+ }
842
+
843
+ impl Iterator for CommentChildrenIterator {
844
+ type Item = Comment ;
845
+ fn next ( & mut self ) -> Option < Comment > {
846
+ if self . index < self . length {
847
+ let idx = self . index ;
848
+ self . index += 1 ;
849
+ Some ( Comment { x : unsafe { clang_Comment_getChild ( self . parent , idx) } } )
850
+ } else {
851
+ None
852
+ }
853
+ }
854
+ }
855
+
843
856
/// A source file.
844
857
pub struct File {
845
858
x : CXFile
Original file line number Diff line number Diff line change @@ -152,8 +152,8 @@ impl Annotations {
152
152
}
153
153
}
154
154
155
- for i in 0 .. comment. num_children ( ) {
156
- self . parse ( & comment . get_child ( i ) . unwrap ( ) , matched) ;
155
+ for child in comment. get_children ( ) {
156
+ self . parse ( & child , matched) ;
157
157
}
158
158
}
159
159
}
You can’t perform that action at this time.
0 commit comments