File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,18 @@ impl<'pr> NodeList<'pr> {
149149 marker : PhantomData ,
150150 }
151151 }
152+
153+ /// Returns the length of the list.
154+ #[ must_use]
155+ pub const fn len ( & self ) -> usize {
156+ unsafe { self . pointer . as_ref ( ) . size }
157+ }
158+
159+ /// Returns whether the list is empty.
160+ #[ must_use]
161+ pub const fn is_empty ( & self ) -> bool {
162+ self . len ( ) == 0
163+ }
152164}
153165
154166impl < ' pr > IntoIterator for & NodeList < ' pr > {
@@ -795,6 +807,8 @@ mod tests {
795807 let result = parse ( source. as_ref ( ) ) ;
796808
797809 let node = result. node ( ) ;
810+ assert_eq ! ( node. as_program_node( ) . unwrap( ) . statements( ) . body( ) . len( ) , 1 ) ;
811+ assert ! ( !node. as_program_node( ) . unwrap( ) . statements( ) . body( ) . is_empty( ) ) ;
798812 let module = node. as_program_node ( ) . unwrap ( ) . statements ( ) . body ( ) . iter ( ) . next ( ) . unwrap ( ) ;
799813 let module = module. as_module_node ( ) . unwrap ( ) ;
800814 let locals = module. locals ( ) . iter ( ) . collect :: < Vec < _ > > ( ) ;
You can’t perform that action at this time.
0 commit comments