Skip to content
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

Update and add enums #99

Merged
merged 5 commits into from
May 14, 2024
Merged

Update and add enums #99

merged 5 commits into from
May 14, 2024

Conversation

rahulchaphalkar
Copy link
Contributor

  • Updated enums for element_type, added From trait
  • Added resize_algorithm enum

impl From<u32> for ElementType {
fn from(value: u32) -> Self {
if value > LARGEST_VARIANT {
return ElementType::Undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as a TryFrom implementation: if the user passes in a u32 value that doesn't line up, we can then return an error instead of silently converting it into ElementType::Undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately, do we need this "from u32" functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think From was needed before this commit. The into() made sense when this was let mut element_type = 0, but I have it initialized as ElementType::Undefined.
So probably can do without From implemented.

return ElementType::Undefined;
}
// SAFETY: ElementType has repr(u32) and the bounds have been checked
unsafe { std::mem::transmute(value) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transmute is pretty unsafe; is there no way to do this by casting?

Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@abrown abrown merged commit faf8c92 into intel:main May 14, 2024
18 checks passed
@rahulchaphalkar rahulchaphalkar deleted the add-enums branch May 17, 2024 22:20
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