Skip to content

Commit

Permalink
Merge branch 'master' into split-multihash
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Mar 21, 2023
2 parents 931016a + 8e14b19 commit 2b426e8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions codetable/examples/custom_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ fn main() {
// Create new hashes from some input data. This is done through the `Code` enum we derived
// Multihash from.
let blake_hash = Code::Blake2b200.digest(b"hello world!");
println!("{:02x?}", blake_hash);
println!("{blake_hash:02x?}");
let truncated_sha2_hash = Code::Sha2_256Truncated20.digest(b"hello world!");
println!("{:02x?}", truncated_sha2_hash);
println!("{truncated_sha2_hash:02x?}");

// Sometimes you might not need to hash new data, you just want to get the information about
// a Multihash.
Expand Down
4 changes: 2 additions & 2 deletions codetable/examples/manual_mh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ fn prefix_util() {

let code_hex = hex::encode(&empty[..1]); // change if longer/shorter prefix
let len_hex = hex::encode(len);
println!("prefix hex: code: {}, len: {}", code_hex, len_hex);
println!("prefix hex: code: {code_hex}, len: {len_hex}");

println!("{}{}{}", code_hex, len_hex, hash);
println!("{code_hex}{len_hex}{hash}");
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion codetable/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
H: Hasher + Default,
{
let digest = hex::decode(digest_str).unwrap();
let expected_bytes = hex::decode(format!("{}{}", prefix, digest_str)).unwrap();
let expected_bytes = hex::decode(format!("{prefix}{digest_str}")).unwrap();
let mut expected_cursor = Cursor::new(&expected_bytes);
let multihash = code.digest(b"hello world");

Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub enum Error {
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::Io(err) => write!(f, "{}", err),
Self::UnsupportedCode(code) => write!(f, "Unsupported multihash code {}.", code),
Self::InvalidSize(size) => write!(f, "Invalid multihash size {}.", size),
Self::Varint(err) => write!(f, "{}", err),
Self::Io(err) => write!(f, "{err}"),
Self::UnsupportedCode(code) => write!(f, "Unsupported multihash code {code}."),
Self::InvalidSize(size) => write!(f, "Invalid multihash size {size}."),
Self::Varint(err) => write!(f, "{err}"),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/multihash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ impl<const S: usize> Multihash<S> {
///
/// let hash = Code::Sha3_256.digest(b"Hello world!");
/// let (.., arr, size) = hash.into_inner();
/// let foo = Foo { arr, len: size as usize };
/// let foo = Foo {
/// arr,
/// len: size as usize,
/// };
/// ```
pub fn into_inner(self) -> (u64, [u8; S], u8) {
let Self { code, digest, size } = self;
Expand Down

0 comments on commit 2b426e8

Please sign in to comment.