Skip to content

Add owned network iterators#114

Open
oschwald wants to merge 1 commit into
mainfrom
greg/owned-within-iterator
Open

Add owned network iterators#114
oschwald wants to merge 1 commit into
mainfrom
greg/owned-within-iterator

Conversation

@oschwald

@oschwald oschwald commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • add Reader::networks_owned() and Reader::within_owned() for callers that need an iterator which owns an Arc<Reader<_>>
  • add OwnedWithin and OwnedLookupResult as owned-reader counterparts to the existing borrowed iterator/result types
  • add tests confirming owned iteration matches borrowed iteration and can decode after the caller drops its original Arc

Tests

  • cargo fmt --all -- --check
  • cargo clippy -- -D warnings
  • cargo test

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced owned variants for network iteration and lookup operations, enabling database readers to remain accessible beyond iterator boundaries.
    • Added owned result types that support deferred decoding while maintaining reader references for greater application flexibility.
    • Expanded public API exports to include new owned variants of core library types for network traversal and lookup result handling.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ad3c29cd-6b87-4be3-8260-70ec9a7db29c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e86128 and 5eaea3f.

📒 Files selected for processing (5)
  • src/lib.rs
  • src/reader.rs
  • src/reader_test.rs
  • src/result.rs
  • src/within.rs

Walkthrough

Adds OwnedLookupResult<S> and OwnedWithin<S> types backed by Arc<Reader<S>>, allowing network iteration iterators to outlive the borrowing scope. New networks_owned and within_owned methods on Reader consume an Arc<Self> and return the owned iterator. Both new types mirror their borrowed counterparts in traversal logic and decode behavior.

Changes

Owned Arc-backed network iteration API

Layer / File(s) Summary
OwnedLookupResult struct and impl
src/result.rs
Introduces OwnedLookupResult<S> storing Arc<Reader<S>> with the same metadata as LookupResult; implements has_data, network, offset, decode, and decode_path with full IPv4/IPv6 subtree and path-error handling.
OwnedWithin iterator
src/within.rs
Adds OwnedWithin<S> struct holding Arc<Reader<S>>, traversal stack, node_count, and WithinOptions; implements Iterator mirroring the borrowed Within depth-first traversal and emitting OwnedLookupResult items; adds push_child and is_empty_value_at helpers.
networks_owned and within_owned reader methods
src/reader.rs
Adds networks_owned(Arc<Self>, options) selecting the full-database CIDR by ip_version and delegating to within_owned, and within_owned(Arc<Self>, cidr, options) validating address-family, computing traversal stack, and constructing OwnedWithin.
Public re-exports and tests
src/lib.rs, src/reader_test.rs
Re-exports OwnedLookupResult and OwnedWithin from the crate root; adds collect_owned_networks helper and two tests verifying owned iteration parity and post-drop decoding.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • oschwald/maxminddb-rust#107: Extracted the push_child helper in the borrowed Within traversal that this PR mirrors when implementing the equivalent logic for OwnedWithin.

Poem

🐇 Hoppity hop, I clutch the Arc tight,
The reader won't vanish before end of night!
OwnedWithin traverses the CIDR tree,
While OwnedLookupResult decodes lazily.
Drop the first Arc — no worries, no fuss,
The networks keep flowing, just trust in us! 🌐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding owned network iterators, which is the primary focus across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch greg/owned-within-iterator

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.

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.

1 participant