-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Use MacAddr instead of String #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
8ad20c7 to
e43c94b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces custom string-based MAC address handling with the MacAddr type from the pnet_base crate.
- Swapped out the
hexmodule andHexSliceformatting forMacAddr::fromconversions. - Updated Windows, Unix, and Linux target code to produce
Option<MacAddr>rather thanOption<String>. - Changed
NetworkInterface.mac_addrto useOption<MacAddr>and re-exportedMacAddrinlib.rs.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/mod.rs | Removed hex module import—no longer needed for MAC formatting |
| src/utils/hex.rs | Deleted custom HexSlice formatter module |
| src/target/windows.rs | Switched Windows MAC parsing to MacAddr, removed HexSlice |
| src/target/unix/mod.rs | Updated Unix MAC parsing to return MacAddr instead of String |
| src/target/linux.rs | Updated Linux MAC parsing to return MacAddr instead of String |
| src/lib.rs | Re-exported MacAddr from the public API |
| src/interface.rs | Changed mac_addr field and builder method to Option<MacAddr> |
| Cargo.toml | Added mac_addr dependency (from pnet_base) and feature flags |
Comments suppressed due to low confidence (4)
src/target/unix/mod.rs:123
- [nitpick] The function name
make_mac_addrsimplies multiple addresses but returns a singleMacAddr. Consider renaming it tomake_mac_addrfor clarity.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {
src/target/linux.rs:123
- [nitpick] The function name
make_mac_addrssuggests multiple addresses but returns a singleMacAddr; renaming tomake_mac_addrwould better reflect its purpose.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {
src/target/unix/mod.rs:123
- There aren’t any unit tests for the Unix
make_mac_addrsconversion. Adding tests for this function would help ensure theMacAddroutput remains correct across platforms.
fn make_mac_addrs(netifa: &libc::ifaddrs) -> MacAddr {
Cargo.toml:18
- [nitpick] Consider marking the
mac_addrdependency as optional (e.g.,optional = true) or documenting its feature flag usage to avoid enlarging the default dependency footprint for consumers who don’t need it.
mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr.
|
|
||
| /// Creates MacAddress from AdapterAddress | ||
| fn make_mac_address(adapter_address: &AdapterAddress) -> MacAddress { | ||
| fn make_mac_address(adapter_address: &AdapterAddress) -> Option<MacAddr> { |
Copilot
AI
Jul 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The byte-to-MacAddr conversion logic is duplicated across Windows, Unix, and Linux modules. Consider extracting this into a shared utility function to reduce code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mokeyish what do you think about this? Do you believe we could centralize this utility?
|
Hi @mokeyish! Thank you so much for your PR! |
LeoBorai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mokeyish,
Overall the changes seems good, Im just wondering if we could have pnet_base being imported explicitly instead of using the package option. Im unsure if theres a benefit on importing crates like that.
Other than that the suggestion from Copilot seems ok to me, perhaps we could follow it and centralize the utility function?
Thank you in advance.
| [dependencies] | ||
| serde = { version = "1.0.183", features = ["derive"], optional = true} | ||
| thiserror = "1.0" | ||
| mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mokeyish I wonder how this differs from importing the crate as:
| mac_addr = { package = "pnet_base", version = "0.35.0"} # It only contains the code for MacAddr. | |
| pnet_base = "0.35" |
closes #36