Multiformats Multihash implementation without constant size in the type signature.
- Uses the [
multiutil::BaseEncoded
] smart pointers to wrap the Multihash into EncodecMultihash for base encoded multihashes; automating the encoding/decoding to/from strings and byte slices. - Serde support to/from human readable and binary formats.
- Supports raw binary encoding and decoding using [
Into<Vec<u8>>
] and [TryFrom<&[u8]>
] trait implementations.
Bulding a multihash from some bytes:
let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
.try_build()?;
Building a base encoded multihash from some bytes:
let encoded_mh = Builder::new_from_bytes(Codec::Sha3256, b"for great justice, move every zig!")?
.with_base_encoding(Base::Base58Btc)
.try_build_encoded()?;
Existing multihash objects can be converted to [crate::mh::EncodedMultihash
]
objects by using .into()
:
let mh = Builder::new_from_bytes(Codec::Sha3384, b"for great justice, move every zig!")?
.try_build()?;
// this will use the preferred encoding for multihash objects: Base::Base16Lower
let encoded_mh1: EncodedMultihash = mh.into();
// or you can chose the base enccoding...
let encoded_mh2: EncodedMultihash::new(Base::Base32Upper, mh);