-
Notifications
You must be signed in to change notification settings - Fork 239
hash2curve
: make hash_to_field
output an array instead of taking an out parameter.
#1296
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
This was attempted before in RustCrypto/traits#872 (comment). AFAICS we decided against it for two reason:
|
I used
I don't think this is really that much of an issue, we are only using the function to generate arrays of 1 or 2 elements, and we may not even want to expose this function publicly. I think out parameters are generally harder to optimize than returning a value: https://www.youtube.com/watch?v=FnGCDLhaxKU&t=5458s, but that may not be true at all & is probably not worth changing a function for it. I don't think this is a big deal at all, feel free to close this PR. I don't want to bikeshed over useless details, this was just something silly I came across when trying to grasp the codebase. I can also refactor to use |
Oh no, this is totally my bad. I totally jumped to conclusions without taking a proper look. This is a great change! And yes, if you could change it to |
hash2curve/src/hash2field.rs
Outdated
T: FromOkm + Default, | ||
C: ArraySize, |
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.
Actually, if we leave this to ArraySize
instead of const C
, we could do the following:
T: FromOkm + Default, | |
C: ArraySize, | |
T: FromOkm + Default, | |
C: ArraySize, | |
T::Length: Mul<C, Output: IsLess<U65536, Output = True>>, |
Eliminating one more run-time error.
However propagating this requirement up for users might be quite ugly. So I'm in favor of actually going ahead with the const generic, but thought I'd drop the thought at least.
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.
Yes this is a good idea, but I don't like the complex trait bounds either. With inline consts we could do something like:
const { if N * T::Length > u16::MAX {
compile_error!("...");
} };
Although this causes non-local errors and so I did not add it for now.
Discussed as part of #1295.