Fix clippy::all lints in tests/examples to unblock 0.7.0 release - #40
Conversation
The release workflow (publish.yml) runs `cargo clippy --all-targets --all-features -- -D clippy::all` on current stable and nightly. Newer clippy (since 0.6.6 shipped) flags lints in the tests and example programs that previously passed, which would block the auto-publish step. The library API and behavior are unchanged. - tests/examples: add explicit transmute::<Src, Dst> annotations (missing_transmute_annotations). - packthru / unsorted-packthru: iterate with enumerate() instead of range indexing (needless_range_loop). - async-passthru: pass &packet (not &mut) to send_packet_to_mstcp (unnecessary_mut_passed). - async examples: sort with sort_by_key(Reverse(..)) (unnecessary sort_by), and allow arc_with_non_send_sync where the async API intentionally shares an Arc<Ndisapi> (Ndisapi owns a raw HANDLE and is deliberately !Send/!Sync). - lib: drop a redundant & in two format! args flagged by nightly clippy. Verified locally on stable and nightly: clippy --all-targets -D clippy::all, cargo test, cargo fmt --check, and cargo publish --dry-run all pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors several examples and source files to improve code quality, readability, and idiomatic Rust usage. Key changes include replacing manual indexing with iterators, removing unnecessary references in format strings, and adding clippy allowances for Arc usage. The review feedback highlights opportunities to further improve safety and idiomaticity by replacing unsafe mem::transmute calls with safe .into() conversions for IP addresses and using the as operator for pointer casting.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR updates test and example code (plus two small format! call adjustments) to satisfy clippy::all on current stable/nightly toolchains so the publish workflow can pass for the 0.7.0 release, without changing library behavior.
Changes:
- Adds explicit type parameters to
mem::transmutecalls in tests/examples to satisfy newer Clippy lints. - Refactors packet-processing loops in examples to avoid
needless_range_loopby iterating withenumerate(). - Tweaks async examples to address
unnecessary_mut_passed,unnecessary sort_by, andarc_with_non_send_synclints.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/netlib/ip_helper/sockaddr_storage.rs | Makes transmute annotations explicit in tests to satisfy missing_transmute_annotations. |
| src/netlib/ip_helper/network_adapter_info.rs | Removes redundant borrow in format! argument (but needs formatting cleanup). |
| src/ndisapi/static_api.rs | Removes redundant borrow in format! argument. |
| examples/unsorted-packthru.rs | Uses iterator + enumerate() instead of index loop to satisfy Clippy. |
| examples/packthru.rs | Uses iterator + enumerate() and passes packet refs directly to request builders. |
| examples/listadapters.rs | Adds explicit transmute type parameters for Clippy (can be simplified to cast). |
| examples/async-passthru.rs | Stops passing &mut where not needed; adds a targeted Clippy allow for Arc<!Send + !Sync>. |
| examples/async-packthru.rs | Uses sort_by_key(Reverse(..)) and adds the targeted Clippy allow for Arc<!Send + !Sync>. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- listadapters: cast the pointer with `.cast::<u8>()` instead of `mem::transmute`, and drop the now-unused `mem` import. - sockaddr_storage tests: build IN_ADDR / IN6_ADDR via the safe `Ipv4Addr` / `Ipv6Addr` `.into()` conversions rather than `unsafe mem::transmute`. - set_friendly_name: fix the `format!` indentation. Verified on stable and nightly: clippy --all-targets -D clippy::all, cargo test, and cargo fmt --check all pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Unblocks the 0.7.0 release. The publish workflow (
publish.yml) gates oncargo clippy --all-targets --all-features -- -D clippy::allacross stable and nightly. Current clippy (1.96 stable / 1.98 nightly) flags lints in the tests and example programs that didn''t exist when 0.6.6 shipped (toolchain drift), which would failstatic-analysisand skip the publish step.The library API and behavior are unchanged — these are test/example fixes plus two cosmetic
format!adjustments in the lib.Changes
missing_transmute_annotations— add explicittransmute::<Src, Dst>in thesockaddr_storagetests andlistadapters.needless_range_loop—packthru/unsorted-packthruiterate withenumerate().unnecessary_mut_passed—async-passthrupasses&packet(not&mut) tosend_packet_to_mstcp.unnecessary sort_by—async-packthruusessort_by_key(Reverse(..)).arc_with_non_send_sync—#[allow]in the async examples, where sharing anArc<Ndisapi>is the intended pattern (Ndisapiowns a rawHANDLEand is deliberately!Send/!Sync).&in twoformat!args (flagged by nightly clippy; would have failed the PR''s ownbuild.ymlnightly leg).Verification (stable + nightly)
cargo clippy --all-targets --all-features -- -D clippy::all— passcargo test— pass (31 unit + 8 doctests)cargo fmt --check— passcargo publish --dry-run— packages and verifies cleanlyAfter this merges, the
0.7.0release/tag can be created to trigger auto-publish.