Open CBenoit opened 2 years ago
It is a bit confusing as both Hasher and StatefulHasher implement Default, but you are explicit about what you want Rust will give it to you.
let hasher: StatefulHasher = Identity256::default();
hopefully this works for you :)
Hi :slightly_smiling_face:
Thank you for the answer, but this is not what I’m looking for.
I need to get a hasher from a hash code I can’t know ahead of time (see my snippet above).
The issue is precisely that we can’t use StatefulHasher
except when using a specific algorithm known at compile-time like you mentioned, which kind of defeat the purpose of multihash to some extend :/
The new API is very nice when using digest
is acceptable though!
I had a look. I currently see no way of doing it with the current code. The way things currently work, you cannot return a StatefulHasher
based on the Code
, as the StatefulHasher
s depend on specific Digest
s (please correct me if I'm wrong).
I've one idea though. Lots of the code is generated. So perhaps we could generate a companion struct to the Code
enum, which implements the StatefulHasher
functionality for all the Code
s. That struct would that returned by a Code::hasher()
call. I'm not sure if that would work, but it might be worth a try.
I had a look. I currently see no way of doing it with the current code. The way things currently work, you cannot return a
StatefulHasher
based on theCode
, as theStatefulHasher
s depend on specificDigest
s (please correct me if I'm wrong).
Exact!
I've one idea though. Lots of the code is generated. So perhaps we could generate a companion struct to the
Code
enum, which implements theStatefulHasher
functionality for all theCode
s. That struct would that returned by aCode::hasher()
call. I'm not sure if that would work, but it might be worth a try.
This would be really helpful!
However, it might not be very straightforward because StatefulHasher
has associated types and implementing structs are using different types (because different digest size).
(because different digest size).
When you derive a Mutlihash
via #[derive(Multihash)]
, all digests should have the same size. So at least that part should work (others may not ;)
Hi,
In previous
multihash
version, we used to be able to compute the digest in a streamed manner usingMultihashDigest::input
and it was possible to get a boxed MultihashDigest given a multihash. I currently see no way of doing the same, which is an issue in some use cases.For example, I need to validate a digest computed from a file. Since the file can be big, I want to use the new
StatefulHasher
trait. However, I found no way to get a trait object.Here’s my code:
If I overlooked something, please let me know!
Thank you