feat: add is_empty method to check if iterator contains no pairs#1132
feat: add is_empty method to check if iterator contains no pairs#1132tomtau merged 1 commit intopest-parser:masterfrom
Conversation
WalkthroughAdds a public Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pest/src/iterators/pairs.rs (1)
377-380: Consider adding test coverage foris_empty.While the implementation is straightforward, consider adding a test to verify the method works correctly for both empty and non-empty
Pairs. You could extend the existingexact_size_iter_for_pairstest or create a dedicated test.Example test:
#[test] fn test_is_empty() { let pairs = AbcParser::parse(Rule::a, "abcde").unwrap(); assert!(!pairs.is_empty()); let mut pairs = AbcParser::parse(Rule::a, "abcde").unwrap(); pairs.next(); pairs.next(); assert!(pairs.is_empty()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pest/src/iterators/pairs.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pest/src/iterators/pairs.rs (1)
pest/src/stack.rs (1)
is_empty(61-63)
🔇 Additional comments (1)
pest/src/iterators/pairs.rs (1)
377-380: No duplicate method declaration found—implementation is correct.The verification confirms only one
is_emptydeclaration exists at line 378. The AI summary's claim of a duplicate was incorrect. The implementation is sound: it correctly checksself.pairs_count == 0and aligns with theExactSizeIterator::len()method. No issues remain.
is_empty is now mostly expected from various iterators - to the point that Clippy suggests adding it, and even AI suggests it for pest despite pest code not supporting it. So to make it more ergonomic, I think this helper would ... help :)
Summary by CodeRabbit
is_empty()method for checking whether a collection contains any elements.