Skip to content

Commit 2ecd49d

Browse files
authored
Merge pull request #3701 from froydnj/froydnj-nodelist-size
2 parents d9dfd19 + 32d4ab0 commit 2ecd49d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rust/ruby-prism/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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

154166
impl<'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<_>>();

0 commit comments

Comments
 (0)