Skip to content

Commit

Permalink
remove per-hash digest type
Browse files Browse the repository at this point in the history
Remove the per-hasher digest type. Instead, store hash digests inside
the hashers and "borrow" it. In all cases, we're going to copy it into a
`Multihash<S>` anyways.

This:

1. Removes bunch of code.
2. Means that hashers don't need to be generic over the size (unless
they actually support multiple sizes). This fixes the UX issue
introduced in the const generics PR.
3. Avoids some copying.

BREAKING CHANGE

1. `Hasher.digest` no longer exists. Users should use
`Code::SomeCode.digest` where possible.
2. The hasher digests no longer exist.
  • Loading branch information
Stebalien committed Nov 4, 2021
1 parent 7fa52a7 commit fcae9c7
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 676 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ use multihash::MultihashCode;
#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
#[mh(code = 0x01, hasher = multihash::Sha2_256, digest = multihash::Sha2Digest<32>)]
#[mh(code = 0x01, hasher = multihash::Sha2_256)]
Foo,
#[mh(code = 0x02, hasher = multihash::Sha2_512, digest = multihash::Sha2Digest<64>)]
#[mh(code = 0x02, hasher = multihash::Sha2_512)]
Bar,
}

Expand Down
4 changes: 2 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
//! #[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
//! #[mh(alloc_size = 64)]
//! pub enum Code {
//! #[mh(code = 0x01, hasher = multihash::Sha2_256, digest = multihash::Sha2Digest<32>)]
//! #[mh(code = 0x01, hasher = multihash::Sha2_256)]
//! Foo,
//! #[mh(code = 0x02, hasher = multihash::Sha2_512, digest = multihash::Sha2Digest<64>)]
//! #[mh(code = 0x02, hasher = multihash::Sha2_512)]
//! Bar,
//! }
//!
Expand Down
Loading

0 comments on commit fcae9c7

Please sign in to comment.