-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
crates/openvino/src/element_type.rs
Outdated
impl From<u32> for ElementType { | ||
fn from(value: u32) -> Self { | ||
if value > LARGEST_VARIANT { | ||
return ElementType::Undefined; |
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.
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
.
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.
Alternately, do we need this "from u32
" functionality?
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.
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.
crates/openvino/src/element_type.rs
Outdated
return ElementType::Undefined; | ||
} | ||
// SAFETY: ElementType has repr(u32) and the bounds have been checked | ||
unsafe { std::mem::transmute(value) } |
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.
transmute
is pretty unsafe; is there no way to do this by casting?
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.
LGTM!
6c1be4d
to
13bbeac
Compare
element_type
, addedFrom
traitresize_algorithm
enum