-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: introduce Multihash::new
which can be called from const contexts
#331
Conversation
Last use of rust-multihash/derive-impl/src/multihash.rs Line 236 in f78d455
Which I think is fine, if not necessary because |
We should also change that to not generate code that is using deprecated functionality. |
Multihash::new
which can be called from const contexts
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.
Do we have other In the issue, you said that the problem is the |
This is not possible without further changes to Neither As an aside, the docs for |
If you'd like my opinion, you should (This would be a breaking change.) |
I've gone ahead and implemented the required changes:
|
Good idea! Would you mind capturing this in an issue?
Yes-ish. |
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.
No objections from my end.
That sounds like a better solution. I would actually prefer that and keep the I'd also be OK with just having the proper solution merged into master and just keep it there before doing a release, in case more breaking changes are uncovered. |
if size > S { | ||
return Err(DigestTooBig(size)); | ||
} |
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 guess we could also flip it and say BufferTooSmall
? The thing is, the size of the internal buffer is part of the public API and likely, cannot be changed as easily so it makes more sense that the digest is too long. Really, this is one of those "should almost never happen"-errors.
The buffer is likely 32 or 64 bytes so you can fit the digests of SHA256 or SHA512 in it.
The issue is that you will have to immediately make a release because I guess that @aatifsyed would want to use this right away. Not upgrading to latest solution is at best a band-aid and means what we might have to do more work later by backporting PRs instead of just being able to merge them into master. An alternative suggestion could be to temporarily introduce a |
Sorry for the week's silence, I was on vacation.
You're correct, but as the rust-cid folks pointed-out1, there's a useable workaround for const fn const_unwrap<T: Copy, E>(r: Result<T, E>) -> T {
let v = match r {
Ok(r) => r,
Err(_) => panic!(),
};
mem::forget(r);
v
} That means forest features are no longer blocked - we can just use I think a lot of the discussion above about error types/API design is valuable, and maybe could be addressed in #332, but this PR (or something like it) can wait until after that. Footnotes |
I agree with that. Thank you for the feedback and input on the error design. We'll incorporate it on the next breaking change :) |
Resolves #330.