File tree 2 files changed +29
-15
lines changed
2 files changed +29
-15
lines changed Original file line number Diff line number Diff line change @@ -785,19 +785,12 @@ impl Comment {
785
785
}
786
786
}
787
787
788
- /// Get the number of children this comment node has.
789
- pub fn num_children ( & self ) -> c_uint {
790
- unsafe {
791
- clang_Comment_getNumChildren ( self . x )
792
- }
793
- }
794
-
795
- /// Get this comment's `idx`th child comment
796
- pub fn get_child ( & self , idx : c_uint ) -> Option < Comment > {
797
- if idx >= self . num_children ( ) {
798
- None
799
- } else {
800
- Some ( Comment { x : unsafe { clang_Comment_getChild ( self . x , idx) } } )
788
+ /// Get this comment's children comment
789
+ pub fn get_children ( & self ) -> CommentChildrenIntoIterator {
790
+ CommentChildrenIntoIterator {
791
+ parent : self . x ,
792
+ length : unsafe { clang_Comment_getNumChildren ( self . x ) } ,
793
+ index : 0
801
794
}
802
795
}
803
796
@@ -834,6 +827,27 @@ impl Comment {
834
827
}
835
828
}
836
829
830
+ /// An iterator for a comment's children
831
+ pub struct CommentChildrenIntoIterator {
832
+ parent : CXComment ,
833
+ length : c_uint ,
834
+ index : c_uint
835
+ }
836
+
837
+ impl Iterator for CommentChildrenIntoIterator {
838
+ type Item = Comment ;
839
+ fn next ( & mut self ) -> Option < Comment > {
840
+ if self . index < self . length {
841
+ let idx = self . index ;
842
+ self . index += 1 ;
843
+ Some ( Comment { x : unsafe { clang_Comment_getChild ( self . parent , idx) } } )
844
+ }
845
+ else {
846
+ None
847
+ }
848
+ }
849
+ }
850
+
837
851
/// A source file.
838
852
pub struct File {
839
853
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