From 29d0d3d65c0b2f42dab68b4f2d8a22d48354e480 Mon Sep 17 00:00:00 2001 From: Ron Kuris Date: Wed, 11 Dec 2024 13:25:00 -0500 Subject: [PATCH] Elide lifetimes (#760) --- firewood/src/db.rs | 2 +- firewood/src/stream.rs | 14 +++++++------- firewood/src/v2/db.rs | 11 ----------- firewood/src/v2/propose.rs | 5 ++++- fwdctl/src/dump.rs | 2 +- storage/src/linear/mod.rs | 1 - storage/src/node/mod.rs | 1 - storage/src/node/path.rs | 6 +++--- storage/src/nodestore.rs | 2 -- storage/src/trie_hash.rs | 2 +- 10 files changed, 17 insertions(+), 29 deletions(-) diff --git a/firewood/src/db.rs b/firewood/src/db.rs index 4564d925e..d862ecb01 100644 --- a/firewood/src/db.rs +++ b/firewood/src/db.rs @@ -225,7 +225,7 @@ pub struct Proposal<'p> { } #[async_trait] -impl<'a> api::DbView for Proposal<'a> { +impl api::DbView for Proposal<'_> { type Stream<'b> = MerkleKeyValueStream<'b, NodeStore, FileBacked>> where diff --git a/firewood/src/stream.rs b/firewood/src/stream.rs index 097f02a2a..ac1023420 100644 --- a/firewood/src/stream.rs +++ b/firewood/src/stream.rs @@ -74,7 +74,7 @@ impl From for NodeStreamState { } } -impl<'a, T: TrieReader> FusedStream for MerkleNodeStream<'a, T> { +impl FusedStream for MerkleNodeStream<'_, T> { fn is_terminated(&self) -> bool { // The top of `iter_stack` is the next node to return. // If `iter_stack` is empty, there are no more nodes to visit. @@ -93,7 +93,7 @@ impl<'a, T: TrieReader> MerkleNodeStream<'a, T> { } } -impl<'a, T: TrieReader> Stream for MerkleNodeStream<'a, T> { +impl Stream for MerkleNodeStream<'_, T> { type Item = Result<(Key, Arc), api::Error>; fn poll_next( @@ -271,13 +271,13 @@ enum MerkleKeyValueStreamState<'a, T> { Initialized { node_iter: MerkleNodeStream<'a, T> }, } -impl<'a, T, K: AsRef<[u8]>> From for MerkleKeyValueStreamState<'a, T> { +impl> From for MerkleKeyValueStreamState<'_, T> { fn from(key: K) -> Self { Self::_Uninitialized(key.as_ref().into()) } } -impl<'a, T: TrieReader> MerkleKeyValueStreamState<'a, T> { +impl MerkleKeyValueStreamState<'_, T> { /// Returns a new iterator that will iterate over all the key-value pairs in `merkle`. fn _new() -> Self { Self::_Uninitialized(Box::new([])) @@ -300,7 +300,7 @@ impl<'a, T: TrieReader> From<&'a T> for MerkleKeyValueStream<'a, T> { } } -impl<'a, T: TrieReader> FusedStream for MerkleKeyValueStream<'a, T> { +impl FusedStream for MerkleKeyValueStream<'_, T> { fn is_terminated(&self) -> bool { matches!(&self.state, MerkleKeyValueStreamState::Initialized { node_iter } if node_iter.is_terminated()) } @@ -317,7 +317,7 @@ impl<'a, T: TrieReader> MerkleKeyValueStream<'a, T> { } } -impl<'a, T: TrieReader> Stream for MerkleKeyValueStream<'a, T> { +impl Stream for MerkleKeyValueStream<'_, T> { type Item = Result<(Key, Value), api::Error>; fn poll_next( @@ -410,7 +410,7 @@ impl<'a, 'b, T: TrieReader> PathIterator<'a, 'b, T> { } } -impl<'a, 'b, T: TrieReader> Iterator for PathIterator<'a, 'b, T> { +impl Iterator for PathIterator<'_, '_, T> { type Item = Result; fn next(&mut self) -> Option { diff --git a/firewood/src/v2/db.rs b/firewood/src/v2/db.rs index c544faca1..ba6d1255e 100644 --- a/firewood/src/v2/db.rs +++ b/firewood/src/v2/db.rs @@ -4,17 +4,6 @@ use crate::db::DbError; use crate::v2::api; -#[cfg_attr(doc, aquamarine::aquamarine)] -/// ```mermaid -/// graph LR -/// RevRootHash --> DBRevID -/// RevHeight --> DBRevID -/// DBRevID -- Identify --> DbRev -/// Db/Proposal -- propose with batch --> Proposal -/// Proposal -- translate --> DbRev -/// DB -- commit proposal --> DB -/// ``` - impl From for api::Error { fn from(value: DbError) -> Self { match value { diff --git a/firewood/src/v2/propose.rs b/firewood/src/v2/propose.rs index a03ab5abc..835ca61d0 100644 --- a/firewood/src/v2/propose.rs +++ b/firewood/src/v2/propose.rs @@ -107,7 +107,10 @@ impl Proposal { #[async_trait] impl api::DbView for Proposal { // TODO: Replace with the correct stream type for an in-memory proposal implementation - type Stream<'a> = Empty, Vec), api::Error>> where T: 'a; + type Stream<'a> + = Empty, Vec), api::Error>> + where + T: 'a; async fn root_hash(&self) -> Result, api::Error> { todo!(); diff --git a/fwdctl/src/dump.rs b/fwdctl/src/dump.rs index 4cfb286b7..1b33342c9 100644 --- a/fwdctl/src/dump.rs +++ b/fwdctl/src/dump.rs @@ -69,5 +69,5 @@ fn u8_to_string(data: &[u8]) -> Cow<'_, str> { } fn key_parser(s: &str) -> Result, std::io::Error> { - return Ok(Box::from(s.as_bytes())); + Ok(Box::from(s.as_bytes())) } diff --git a/storage/src/linear/mod.rs b/storage/src/linear/mod.rs index e60755b2a..016776666 100644 --- a/storage/src/linear/mod.rs +++ b/storage/src/linear/mod.rs @@ -37,7 +37,6 @@ pub trait ReadableStorage: Debug + Sync + Send { /// # Returns /// /// A `Result` containing a boxed `Read` trait object, or an `Error` if the operation fails. - fn stream_from(&self, addr: u64) -> Result, Error>; /// Return the size of the underlying storage, in bytes diff --git a/storage/src/node/mod.rs b/storage/src/node/mod.rs index 554b3f352..7c67e49fb 100644 --- a/storage/src/node/mod.rs +++ b/storage/src/node/mod.rs @@ -464,7 +464,6 @@ pub struct PathIterItem { } #[cfg(test)] - mod test { use crate::{ node::{BranchNode, LeafNode, Node}, diff --git a/storage/src/node/path.rs b/storage/src/node/path.rs index 777d1a395..4b34e7f8f 100644 --- a/storage/src/node/path.rs +++ b/storage/src/node/path.rs @@ -152,9 +152,9 @@ pub struct NibblesIterator<'a> { tail: usize, } -impl<'a> FusedIterator for NibblesIterator<'a> {} +impl FusedIterator for NibblesIterator<'_> {} -impl<'a> Iterator for NibblesIterator<'a> { +impl Iterator for NibblesIterator<'_> { type Item = u8; #[cfg(feature = "branch_factor_256")] @@ -216,7 +216,7 @@ impl<'a> NibblesIterator<'a> { } } -impl<'a> DoubleEndedIterator for NibblesIterator<'a> { +impl DoubleEndedIterator for NibblesIterator<'_> { fn next_back(&mut self) -> Option { if self.is_empty() { return None; diff --git a/storage/src/nodestore.rs b/storage/src/nodestore.rs index ebe3641e6..34e3ba6d4 100644 --- a/storage/src/nodestore.rs +++ b/storage/src/nodestore.rs @@ -167,7 +167,6 @@ fn area_size_to_index(n: u64) -> Result { pub type LinearAddress = NonZeroU64; /// Each [StoredArea] contains an [Area] which is either a [Node] or a [FreeArea]. - #[repr(u8)] #[derive(PartialEq, Eq, Clone, Debug, Deserialize, Serialize)] enum Area { @@ -600,7 +599,6 @@ impl NodeStoreHeader { /// The first SIZE bytes of the ReadableStorage are reserved for the /// [NodeStoreHeader]. /// We also want it aligned to a disk block - const SIZE: u64 = 2048; /// Number of extra bytes to write on the first creation of the NodeStoreHeader diff --git a/storage/src/trie_hash.rs b/storage/src/trie_hash.rs index 89df4b061..0f48000a6 100644 --- a/storage/src/trie_hash.rs +++ b/storage/src/trie_hash.rs @@ -81,7 +81,7 @@ impl<'de> Deserialize<'de> for TrieHash { struct TrieVisitor; -impl<'de> Visitor<'de> for TrieVisitor { +impl Visitor<'_> for TrieVisitor { type Value = TrieHash; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {