-
Notifications
You must be signed in to change notification settings - Fork 11
Implement From<u32> for FwVersion #28
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
Implement From<u32> for FwVersion #28
Conversation
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 implements the From<u32> trait for the FwVersion struct to enable idiomatic Rust conversion from u32 values to FwVersion instances. The conversion extracts the firmware version components (variant, minor, and major) from a u32 using bit manipulation, and is the inverse of the existing From<FwVersion> for u32 implementation.
Changes:
- Adds
From<u32>trait implementation forFwVersionstruct using bit shifts and masks to extract version components
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| impl From<u32> for FwVersion { | ||
| fn from(ver: u32) -> Self { | ||
| Self { | ||
| variant: (ver & 0xFF) as u8, | ||
| minor: ((ver >> 8) & 0xFFFF) as u16, | ||
| major: ((ver >> 24) & 0xFF) as u8, | ||
| } | ||
| } | ||
| } |
Copilot
AI
Jan 21, 2026
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 From implementation duplicates the existing FwVersion::new() method (lines 28-34). Consider deprecating FwVersion::new() in favor of using From::from() consistently throughout the codebase, or remove this From implementation if FwVersion::new() is preferred. Having both can lead to inconsistency in how FwVersion instances are created from u32 values.
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.
Why do we need this? Can't we just call new()?
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.
@jerrysxie Was used from ADO side, not need for now, close this PR.
| impl From<u32> for FwVersion { | ||
| fn from(ver: u32) -> Self { | ||
| Self { | ||
| variant: (ver & 0xFF) as u8, | ||
| minor: ((ver >> 8) & 0xFFFF) as u16, | ||
| major: ((ver >> 24) & 0xFF) as u8, | ||
| } | ||
| } | ||
| } |
Copilot
AI
Jan 21, 2026
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.
Consider adding tests for the From and From trait implementations to verify that conversion between FwVersion and u32 is bidirectional and preserves values correctly. The test module (starting at line 1082) includes tests for other protocol structures but lacks coverage for these conversion traits.
No description provided.