-
Notifications
You must be signed in to change notification settings - Fork 57
feat(rad): new RadonInteger operators #2650
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
Conversation
b78c193 to
1f79501
Compare
| } | ||
| } | ||
|
|
||
| pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> { |
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 always assumed that an eventual Integer::to_bytes method would take the preferred endianness as an argument (even if we default to Big Endian)
@guidiaz What do you think?
| (RadonOpCodes::IntegerToBytes, None) => integer_operators::to_bytes(self.clone()) | ||
| .map(RadonTypes::from), | ||
| (RadonOpCodes::IntegerToFloat, None) => { | ||
| integer_operators::to_float(self.clone()).map(RadonTypes::from) |
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.
We can stick to Into::into for uniformity:
| integer_operators::to_float(self.clone()).map(RadonTypes::from) | |
| integer_operators::to_float(self.clone()).map(Into::into) |
| } | ||
| } | ||
|
|
||
| pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> { |
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.
In this case, it is better to receive the argument by reference to avoid redundant cloning:
| pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> { | |
| pub fn to_bytes(input: &RadonInteger) -> Result<RadonBytes, RadError> { |
I know you followed what to_float and to_string had in place, but that's not needed anymore with modern Rust 💪
| let mut bytes_array = [0u8; 16]; | ||
| bytes_array.copy_from_slice(&input.value().to_be_bytes()); |
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 should work just as well and benefit from lesser allocation and runtime:
| let mut bytes_array = [0u8; 16]; | |
| bytes_array.copy_from_slice(&input.value().to_be_bytes()); | |
| let bytes_array = input.value().to_be_bytes(); |
No description provided.