From 1e12ba1bcebc5161605fed0739102d6285ff46e2 Mon Sep 17 00:00:00 2001 From: Tobi Demeco Date: Thu, 14 Nov 2024 13:40:10 -0300 Subject: [PATCH] fmt with nightly --- substrate/primitives/trie/src/node_codec.rs | 45 +++++++++------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/substrate/primitives/trie/src/node_codec.rs b/substrate/primitives/trie/src/node_codec.rs index 16cddc2b037a..27da0c6334a2 100644 --- a/substrate/primitives/trie/src/node_codec.rs +++ b/substrate/primitives/trie/src/node_codec.rs @@ -44,7 +44,7 @@ impl<'a> ByteSliceInput<'a> { fn take(&mut self, count: usize) -> Result, codec::Error> { if self.offset + count > self.data.len() { - return Err("out of data".into()); + return Err("out of data".into()) } let range = self.offset..(self.offset + count); @@ -66,7 +66,7 @@ impl<'a> Input for ByteSliceInput<'a> { fn read_byte(&mut self) -> Result { if self.offset + 1 > self.data.len() { - return Err("out of data".into()); + return Err("out of data".into()) } let byte = self.data[self.offset]; @@ -112,15 +112,15 @@ where let padding = nibble_count % nibble_ops::NIBBLE_PER_BYTE != 0; // data should be at least the size of the offset if data.len() < input.offset { - return Err(Error::BadFormat); + return Err(Error::BadFormat) } // check that the padding is valid (if any) if padding && nibble_ops::pad_left(data[input.offset]) != 0 { - return Err(Error::BadFormat); + return Err(Error::BadFormat) } let partial = input.take( - (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) - / nibble_ops::NIBBLE_PER_BYTE, + (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) / + nibble_ops::NIBBLE_PER_BYTE, )?; let partial_padding = nibble_ops::number_padding(nibble_count); let bitmap_range = input.take(BITMAP_LENGTH)?; @@ -160,15 +160,15 @@ where let padding = nibble_count % nibble_ops::NIBBLE_PER_BYTE != 0; // data should be at least the size of the offset if data.len() < input.offset { - return Err(Error::BadFormat); + return Err(Error::BadFormat) } // check that the padding is valid (if any) if padding && nibble_ops::pad_left(data[input.offset]) != 0 { - return Err(Error::BadFormat); + return Err(Error::BadFormat) } let partial = input.take( - (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) - / nibble_ops::NIBBLE_PER_BYTE, + (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) / + nibble_ops::NIBBLE_PER_BYTE, )?; let partial_padding = nibble_ops::number_padding(nibble_count); let value = if contains_hash { @@ -237,15 +237,12 @@ where ) -> Vec { let contains_hash = matches!(&value, Some(Value::Node(..))); let mut output = match (&value, contains_hash) { - (&None, _) => { - partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchNoValue) - }, - (_, false) => { - partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchWithValue) - }, - (_, true) => { - partial_from_iterator_encode(partial, number_nibble, NodeKind::HashedValueBranch) - }, + (&None, _) => + partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchNoValue), + (_, false) => + partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchWithValue), + (_, true) => + partial_from_iterator_encode(partial, number_nibble, NodeKind::HashedValueBranch), }; let bitmap_index = output.len(); @@ -296,12 +293,10 @@ fn partial_from_iterator_encode>( NodeKind::Leaf => NodeHeader::Leaf(nibble_count).encode_to(&mut output), NodeKind::BranchWithValue => NodeHeader::Branch(true, nibble_count).encode_to(&mut output), NodeKind::BranchNoValue => NodeHeader::Branch(false, nibble_count).encode_to(&mut output), - NodeKind::HashedValueLeaf => { - NodeHeader::HashedValueLeaf(nibble_count).encode_to(&mut output) - }, - NodeKind::HashedValueBranch => { - NodeHeader::HashedValueBranch(nibble_count).encode_to(&mut output) - }, + NodeKind::HashedValueLeaf => + NodeHeader::HashedValueLeaf(nibble_count).encode_to(&mut output), + NodeKind::HashedValueBranch => + NodeHeader::HashedValueBranch(nibble_count).encode_to(&mut output), }; output.extend(partial); output