@@ -51,22 +51,19 @@ impl Drop for SignatureNode {
5151 }
5252}
5353
54- pub struct NodeListIter {
55- parser : * mut rbs_parser_t ,
56- current : * mut rbs_node_list_node_t ,
57- }
58-
59- impl Iterator for NodeListIter {
60- type Item = Node ;
54+ impl KeywordNode {
55+ pub fn name ( & self ) -> & [ u8 ] {
56+ unsafe {
57+ let constant_ptr = rbs_constant_pool_id_to_constant (
58+ & ( * self . parser ) . constant_pool ,
59+ ( * self . pointer ) . constant_id ,
60+ ) ;
61+ if constant_ptr. is_null ( ) {
62+ panic ! ( "Constant ID for keyword is not present in the pool" ) ;
63+ }
6164
62- fn next ( & mut self ) -> Option < Self :: Item > {
63- if self . current . is_null ( ) {
64- None
65- } else {
66- let pointer_data = unsafe { * self . current } ;
67- let node = Node :: new ( self . parser , pointer_data. node ) ;
68- self . current = pointer_data. next ;
69- Some ( node)
65+ let constant = & * constant_ptr;
66+ std:: slice:: from_raw_parts ( constant. start , constant. length )
7067 }
7168 }
7269}
@@ -91,6 +88,26 @@ impl NodeList {
9188 }
9289}
9390
91+ pub struct NodeListIter {
92+ parser : * mut rbs_parser_t ,
93+ current : * mut rbs_node_list_node_t ,
94+ }
95+
96+ impl Iterator for NodeListIter {
97+ type Item = Node ;
98+
99+ fn next ( & mut self ) -> Option < Self :: Item > {
100+ if self . current . is_null ( ) {
101+ None
102+ } else {
103+ let pointer_data = unsafe { * self . current } ;
104+ let node = Node :: new ( self . parser , pointer_data. node ) ;
105+ self . current = pointer_data. next ;
106+ Some ( node)
107+ }
108+ }
109+ }
110+
94111pub struct RBSHash {
95112 parser : * mut rbs_parser_t ,
96113 pointer : * mut rbs_hash ,
@@ -150,6 +167,24 @@ impl RBSLocation {
150167 }
151168}
152169
170+ pub struct RBSLocationList {
171+ pointer : * mut rbs_location_list ,
172+ }
173+
174+ impl RBSLocationList {
175+ pub fn new ( pointer : * mut rbs_location_list ) -> Self {
176+ Self { pointer }
177+ }
178+
179+ /// Returns an iterator over the locations.
180+ #[ must_use]
181+ pub fn iter ( & self ) -> RBSLocationListIter {
182+ RBSLocationListIter {
183+ current : unsafe { ( * self . pointer ) . head } ,
184+ }
185+ }
186+ }
187+
153188pub struct RBSLocationListIter {
154189 current : * mut rbs_location_list_node_t ,
155190}
@@ -169,24 +204,6 @@ impl Iterator for RBSLocationListIter {
169204 }
170205}
171206
172- pub struct RBSLocationList {
173- pointer : * mut rbs_location_list ,
174- }
175-
176- impl RBSLocationList {
177- pub fn new ( pointer : * mut rbs_location_list ) -> Self {
178- Self { pointer }
179- }
180-
181- /// Returns an iterator over the locations.
182- #[ must_use]
183- pub fn iter ( & self ) -> RBSLocationListIter {
184- RBSLocationListIter {
185- current : unsafe { ( * self . pointer ) . head } ,
186- }
187- }
188- }
189-
190207#[ derive( Debug ) ]
191208pub struct RBSString {
192209 pointer : * const rbs_string_t ,
@@ -222,23 +239,6 @@ impl SymbolNode {
222239 }
223240}
224241
225- impl KeywordNode {
226- pub fn name ( & self ) -> & [ u8 ] {
227- unsafe {
228- let constant_ptr = rbs_constant_pool_id_to_constant (
229- & ( * self . parser ) . constant_pool ,
230- ( * self . pointer ) . constant_id ,
231- ) ;
232- if constant_ptr. is_null ( ) {
233- panic ! ( "Constant ID for keyword is not present in the pool" ) ;
234- }
235-
236- let constant = & * constant_ptr;
237- std:: slice:: from_raw_parts ( constant. start , constant. length )
238- }
239- }
240- }
241-
242242#[ cfg( test) ]
243243mod tests {
244244 use super :: * ;
0 commit comments