Skip to content

Add IpHeadersSlice and IpSlice::header()#136

Merged
JulianSchmid merged 1 commit intoJulianSchmid:masterfrom
xyzzyz:amichalik/ipheaders-from-slice
Mar 7, 2026
Merged

Add IpHeadersSlice and IpSlice::header()#136
JulianSchmid merged 1 commit intoJulianSchmid:masterfrom
xyzzyz:amichalik/ipheaders-from-slice

Conversation

@xyzzyz
Copy link
Contributor

@xyzzyz xyzzyz commented Feb 22, 2026

Introduce IpHeadersSlice as an enum over Ipv4HeaderSlice and Ipv6HeaderSlice, with convenience accessors and conversion to IpHeaders.

Add IpSlice::header() to that returns IpHeadersSlice. Add IpSlice::to_header that returns IpHeaders

Summary by CodeRabbit

  • New Features

    • Enhanced IP header access and manipulation capabilities with unified handling for IPv4 and IPv6 variants.
    • Improved conversion utilities for seamless transformation between header representations.
  • Tests

    • Comprehensive test coverage for header operations, including round-trip validation and cross-variant consistency checks.

Introduce IpHeadersSlice as an enum over Ipv4HeaderSlice and Ipv6HeaderSlice, with convenience accessors and conversion to IpHeaders. Add IpSlice::header() to expose base IP header slices, export the new net module, and extend tests with unit and proptest coverage for conversion consistency and round-trip invariants.
@JulianSchmid JulianSchmid force-pushed the amichalik/ipheaders-from-slice branch from 5ba0b0d to 1f5ef52 Compare March 6, 2026 19:34
@JulianSchmid
Copy link
Owner

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a68052f8-3106-4f29-9d65-1a4b80ac9a39

📥 Commits

Reviewing files that changed from the base of the PR and between bcc669d and 1f5ef52.

📒 Files selected for processing (3)
  • etherparse/src/net/ip_headers_slice.rs
  • etherparse/src/net/ip_slice.rs
  • etherparse/src/net/mod.rs

📝 Walkthrough

Walkthrough

A new IpHeadersSlice enum is introduced to represent IPv4/IPv6 base headers with their respective extension headers. The enum provides comprehensive accessors for source address, destination address, and header metadata, along with conversion methods. Two methods are added to IpSlice to expose this interface through header() and to_header(). The new module is properly registered and exported.

Changes

Cohort / File(s) Summary
New IP Headers Slice Module
etherparse/src/net/ip_headers_slice.rs
Introduces IpHeadersSlice<'a> enum with IPv4 and IPv6 variants, each paired with their extension headers. Provides accessor methods for header fields (source/destination addresses, next header, version, length) and try_to_header() conversion. Includes comprehensive unit tests for both IPv4 and IPv6 paths.
IP Slice Methods
etherparse/src/net/ip_slice.rs
Adds header() method to extract IpHeadersSlice from an IpSlice, and to_header() method to convert back to IpHeaders. Extensive test coverage includes round-trip validation and coherence checks for both IPv4 and IPv6 variants using unit and property-based tests.
Module Registration
etherparse/src/net/mod.rs
Declares and re-exports the new ip_headers_slice module, making IpHeadersSlice and related types publicly accessible through the net module namespace.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 New slices dancing, headers bright,
IPv4 and IPv6 in flight,
Accessors hop and converters play,
Extensions bundled every way! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: introduction of IpHeadersSlice and the header() method on IpSlice.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@JulianSchmid JulianSchmid merged commit 8100ff5 into JulianSchmid:master Mar 7, 2026
10 checks passed
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (bcc669d) to head (1f5ef52).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@      Coverage Diff      @@
##   master   #136   +/-   ##
=============================
=============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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