Giter Club home page Giter Club logo

Comments (5)

vmx avatar vmx commented on June 12, 2024 1

(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 ;)

from rust-multihash.

mriise avatar mriise commented on June 12, 2024

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 :)

from rust-multihash.

CBenoit avatar CBenoit commented on June 12, 2024

Hi πŸ™‚

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!

from rust-multihash.

vmx avatar vmx commented on June 12, 2024

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 StatefulHashers depend on specific Digests (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 Codes. 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.

from rust-multihash.

CBenoit avatar CBenoit commented on June 12, 2024

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 StatefulHashers depend on specific Digests (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 the StatefulHasher functionality for all the Codes. 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.

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).

from rust-multihash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.