Skip to content

Conversation

@zhuyi2024
Copy link

No description provided.

Copilot AI review requested due to automatic review settings January 21, 2026 06:56
@zhuyi2024 zhuyi2024 requested a review from a team as a code owner January 21, 2026 06:56
Copy link

Copilot AI left a 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 for FwVersion struct using bit shifts and masks to extract version components

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +51
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,
}
}
}
Copy link

Copilot AI Jan 21, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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()?

Copy link
Author

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.

Comment on lines +43 to +51
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,
}
}
}
Copy link

Copilot AI Jan 21, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants