Skip to content

Conversation

@nyurik
Copy link
Contributor

@nyurik nyurik commented Oct 24, 2025

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

  • New Features
    • Added is_empty() method for checking whether a collection contains any elements.

@nyurik nyurik requested a review from a team as a code owner October 24, 2025 23:32
@nyurik nyurik requested review from tomtau and removed request for a team October 24, 2025 23:32
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Walkthrough

Adds a public is_empty method to the Pairs<'i, R> struct that returns a boolean indicating whether the internal pairs_count is zero. The implementation is a straightforward equality check without additional logic or control-flow modifications.

Changes

Cohort / File(s) Change Summary
Add is_empty method to Pairs
pest/src/iterators/pairs.rs
Added public is_empty(&self) -> bool method to Pairs<'i, R> that checks if pairs_count == 0

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Critical attention needed: The summary indicates the is_empty method appears twice in the impl block, resulting in duplicate declarations. Verify that only one definition exists in the final code, as duplicate method declarations would cause a compilation error.

Poem

🐰 A pair that's empty, bare and light,
Now has a method, clear and bright!
Just check is_empty, swift and clean,
The simplest check we've ever seen!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat: add is_empty method to check if iterator contains no pairs" directly and accurately describes the main change in this pull request. It uses conventional commit format with "feat:" prefix, clearly states what was added (the is_empty method), and explains its purpose (to check if an iterator contains no pairs). The title is concise at 11 words, avoids vague terminology, and provides sufficient specificity for a teammate reviewing the commit history to understand the primary change without needing to inspect the diff.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
pest/src/iterators/pairs.rs (1)

377-380: Consider adding test coverage for is_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 existing exact_size_iter_for_pairs test 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

📥 Commits

Reviewing files that changed from the base of the PR and between d2dd16c and a8a98ac.

📒 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_empty declaration exists at line 378. The AI summary's claim of a duplicate was incorrect. The implementation is sound: it correctly checks self.pairs_count == 0 and aligns with the ExactSizeIterator::len() method. No issues remain.

@tomtau tomtau merged commit c51e047 into pest-parser:master Oct 26, 2025
9 checks passed
@nyurik nyurik deleted the is_empty branch October 26, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants