Skip to content

Commit

Permalink
fmt with nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
TDemeco committed Nov 14, 2024
1 parent 34f3d40 commit 1e12ba1
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions substrate/primitives/trie/src/node_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a> ByteSliceInput<'a> {

fn take(&mut self, count: usize) -> Result<Range<usize>, 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);
Expand All @@ -66,7 +66,7 @@ impl<'a> Input for ByteSliceInput<'a> {

fn read_byte(&mut self) -> Result<u8, codec::Error> {
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];
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -237,15 +237,12 @@ where
) -> Vec<u8> {
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();
Expand Down Expand Up @@ -296,12 +293,10 @@ fn partial_from_iterator_encode<I: Iterator<Item = u8>>(
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
Expand Down

0 comments on commit 1e12ba1

Please sign in to comment.