diff --git a/memorydb/src/lib.rs b/memorydb/src/lib.rs index c7397a9..903f4ee 100644 --- a/memorydb/src/lib.rs +++ b/memorydb/src/lib.rs @@ -88,14 +88,20 @@ pub struct MemoryDB { null_node_data: T, } -impl<'a, H, T> Default for MemoryDB where H: KeyHasher, H::Out: HeapSizeOf, T: From<&'a [u8]> { +impl<'a, H, T> Default for MemoryDB +where + H: KeyHasher, + H::Out: HeapSizeOf, + T: From<&'a [u8]> +{ fn default() -> Self { Self::new() } } impl<'a, H, T> MemoryDB - where H: KeyHasher, - H::Out: HeapSizeOf, - T: From<&'a [u8]>, +where + H: KeyHasher, + H::Out: HeapSizeOf, + T: From<&'a [u8]>, { /// Create a new instance of the memory DB. pub fn new() -> Self { @@ -104,9 +110,10 @@ impl<'a, H, T> MemoryDB } impl MemoryDB - where H: KeyHasher, - H::Out: HeapSizeOf, - T: Default, +where + H: KeyHasher, + H::Out: HeapSizeOf, + T: Default, { /// Remove an element and delete it from storage if reference count reaches zero. /// If the value was purged, return the old value. @@ -208,9 +215,10 @@ impl MemoryDB { } impl MemoryDB - where H: KeyHasher, - H::Out: HeapSizeOf, - T: HeapSizeOf, +where + H: KeyHasher, + H::Out: HeapSizeOf, + T: HeapSizeOf, { /// Returns the size of allocated heap memory pub fn mem_used(&self) -> usize { @@ -219,8 +227,9 @@ impl MemoryDB } impl HashDB for MemoryDB - where H: KeyHasher, - T: Default + PartialEq + for<'a> From<&'a [u8]> + Send + Sync, +where + H: KeyHasher, + T: Default + PartialEq + for<'a> From<&'a [u8]> + Send + Sync, { fn keys(&self) -> HashMap { self.data.iter() @@ -312,8 +321,9 @@ impl HashDB for MemoryDB } impl AsHashDB for MemoryDB - where H: KeyHasher, - T: Default + PartialEq + for<'a> From<&'a[u8]> + Send + Sync, +where + H: KeyHasher, + T: Default + PartialEq + for<'a> From<&'a[u8]> + Send + Sync, { fn as_hashdb(&self) -> &HashDB { self } fn as_hashdb_mut(&mut self) -> &mut HashDB { self } diff --git a/patricia_trie/src/triedbmut.rs b/patricia_trie/src/triedbmut.rs index e174c85..ebe585e 100644 --- a/patricia_trie/src/triedbmut.rs +++ b/patricia_trie/src/triedbmut.rs @@ -77,11 +77,19 @@ enum Node { Branch(Box<[Option>; 16]>, Option) } -impl Node where O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy { +impl Node +where + O: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy +{ // load an inline node into memory or get the hash to do the lookup later. - fn inline_or_hash(node: &[u8], db: &HashDB, storage: &mut NodeStorage) -> NodeHandle - where C: NodeCodec, - H: Hasher, + fn inline_or_hash( + node: &[u8], + db: &HashDB, + storage: &mut NodeStorage + ) -> NodeHandle + where + C: NodeCodec, + H: Hasher, { C::try_decode_hash(&node) .map(NodeHandle::Hash) @@ -976,8 +984,15 @@ mod tests { use ethereum_types::H256; use DBValue; - fn populate_trie<'db, H, C>(db: &'db mut HashDB, root: &'db mut H256, v: &[(Vec, Vec)]) -> TrieDBMut<'db> - where H: Hasher, H::Out: Decodable + Encodable, C: NodeCodec + fn populate_trie<'db, H, C>( + db: &'db mut HashDB, + root: &'db mut H256, + v: &[(Vec, Vec)] + ) -> TrieDBMut<'db> + where + H: Hasher, + H::Out: Decodable + Encodable, + C: NodeCodec, { let mut t = TrieDBMut::new(db, root); for i in 0..v.len() { diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index 3fd8106..6b608fc 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -64,10 +64,10 @@ impl RlpStream { /// use rlp::*; /// /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append_empty_data().append_empty_data(); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc2, 0x80, 0x80]); + /// let mut stream = RlpStream::new_list(2); + /// stream.append_empty_data().append_empty_data(); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc2, 0x80, 0x80]); /// } /// ``` pub fn append_empty_data(&mut self) -> &mut Self { @@ -105,10 +105,10 @@ impl RlpStream { /// use rlp::*; /// /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append(&"cat").append(&"dog"); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); + /// let mut stream = RlpStream::new_list(2); + /// stream.append(&"cat").append(&"dog"); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// } /// ``` pub fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: Encodable { @@ -143,11 +143,11 @@ impl RlpStream { /// use rlp::*; /// /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.begin_list(2).append(&"cat").append(&"dog"); - /// stream.append(&""); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]); + /// let mut stream = RlpStream::new_list(2); + /// stream.begin_list(2).append(&"cat").append(&"dog"); + /// stream.append(&""); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]); /// } /// ``` pub fn begin_list(&mut self, len: usize) -> &mut RlpStream { @@ -221,12 +221,12 @@ impl RlpStream { /// use rlp::*; /// /// fn main () { - /// let mut stream = RlpStream::new_list(3); - /// stream.append(&"cat"); - /// stream.clear(); - /// stream.append(&"dog"); - /// let out = stream.out(); - /// assert_eq!(out, vec![0x83, b'd', b'o', b'g']); + /// let mut stream = RlpStream::new_list(3); + /// stream.append(&"cat"); + /// stream.clear(); + /// stream.append(&"dog"); + /// let out = stream.out(); + /// assert_eq!(out, vec![0x83, b'd', b'o', b'g']); /// } pub fn clear(&mut self) { // clear bytes @@ -243,13 +243,13 @@ impl RlpStream { /// use rlp::*; /// /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append(&"cat"); - /// assert_eq!(stream.is_finished(), false); - /// stream.append(&"dog"); - /// assert_eq!(stream.is_finished(), true); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); + /// let mut stream = RlpStream::new_list(2); + /// stream.append(&"cat"); + /// assert_eq!(stream.is_finished(), false); + /// stream.append(&"dog"); + /// assert_eq!(stream.is_finished(), true); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// } pub fn is_finished(&self) -> bool { self.unfinished_lists.len() == 0 @@ -266,7 +266,6 @@ impl RlpStream { /// panic! if stream is not finished. pub fn out(self) -> Vec { match self.is_finished() { - //true => self.encoder.out().into_vec(), true => self.buffer, false => panic!() } diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 37b5a72..8f02989 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -49,10 +49,11 @@ fn shared_prefix_len(first: &[T], second: &[T]) -> usize { /// } /// ``` pub fn ordered_trie_root(input: I) -> H::Out - where I: IntoIterator, - A: AsRef<[u8]>, - H: Hasher, - ::Out: cmp::Ord + rlp::Encodable, +where + I: IntoIterator, + A: AsRef<[u8]>, + H: Hasher, + ::Out: cmp::Ord + rlp::Encodable, { let gen_input: Vec<_> = input // first put elements into btree to sort them by nibbles (key'd by index) @@ -89,11 +90,12 @@ pub fn ordered_trie_root(input: I) -> H::Out /// } /// ``` pub fn trie_root(input: I) -> H::Out - where I: IntoIterator, - A: AsRef<[u8]> + Ord, - B: AsRef<[u8]>, - H: Hasher, - ::Out: cmp::Ord + rlp::Encodable, +where + I: IntoIterator, + A: AsRef<[u8]> + Ord, + B: AsRef<[u8]>, + H: Hasher, + ::Out: cmp::Ord + rlp::Encodable, { let gen_input: Vec<_> = input // first put elements into btree to sort them and to remove duplicates @@ -127,11 +129,12 @@ pub fn trie_root(input: I) -> H::Out /// } /// ``` pub fn sec_trie_root(input: I) -> H::Out - where I: IntoIterator, - A: AsRef<[u8]>, - B: AsRef<[u8]>, - H: Hasher, - ::Out: cmp::Ord + rlp::Encodable, +where + I: IntoIterator, + A: AsRef<[u8]>, + B: AsRef<[u8]>, + H: Hasher, + ::Out: cmp::Ord + rlp::Encodable, { let gen_input: Vec<_> = input // first put elements into btree to sort them and to remove duplicates @@ -147,11 +150,11 @@ pub fn sec_trie_root(input: I) -> H::Out } fn gen_trie_root(input: &[(A, B)]) -> H::Out - where - A: AsRef<[u8]>, - B: AsRef<[u8]>, - H: Hasher, - ::Out: cmp::Ord + rlp::Encodable, +where + A: AsRef<[u8]>, + B: AsRef<[u8]>, + H: Hasher, + ::Out: cmp::Ord + rlp::Encodable, { let mut stream = RlpStream::new(); hash256rlp::(input, 0, &mut stream); @@ -214,11 +217,11 @@ fn as_nibbles(bytes: &[u8]) -> ElasticArray8 { } fn hash256rlp(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream) - where - A: AsRef<[u8]>, - B: AsRef<[u8]>, - H: Hasher, - ::Out: rlp::Encodable, +where + A: AsRef<[u8]>, + B: AsRef<[u8]>, + H: Hasher, + ::Out: rlp::Encodable, { let inlen = input.len(); @@ -297,11 +300,11 @@ fn hash256rlp(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream) } fn hash256aux(input: &[(A, B)], pre_len: usize, stream: &mut RlpStream) - where - A: AsRef<[u8]>, - B: AsRef<[u8]>, - H: Hasher, - ::Out: rlp::Encodable, +where + A: AsRef<[u8]>, + B: AsRef<[u8]>, + H: Hasher, + ::Out: rlp::Encodable, { let mut s = RlpStream::new(); hash256rlp::(input, pre_len, &mut s);