Skip to content

Commit

Permalink
Elide lifetimes (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Dec 11, 2024
1 parent a9b1546 commit 29d0d3d
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<ImmutableProposal>, FileBacked>>
where
Expand Down
14 changes: 7 additions & 7 deletions firewood/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl From<Key> for NodeStreamState {
}
}

impl<'a, T: TrieReader> FusedStream for MerkleNodeStream<'a, T> {
impl<T: TrieReader> 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.
Expand All @@ -93,7 +93,7 @@ impl<'a, T: TrieReader> MerkleNodeStream<'a, T> {
}
}

impl<'a, T: TrieReader> Stream for MerkleNodeStream<'a, T> {
impl<T: TrieReader> Stream for MerkleNodeStream<'_, T> {
type Item = Result<(Key, Arc<Node>), api::Error>;

fn poll_next(
Expand Down Expand Up @@ -271,13 +271,13 @@ enum MerkleKeyValueStreamState<'a, T> {
Initialized { node_iter: MerkleNodeStream<'a, T> },
}

impl<'a, T, K: AsRef<[u8]>> From<K> for MerkleKeyValueStreamState<'a, T> {
impl<T, K: AsRef<[u8]>> From<K> for MerkleKeyValueStreamState<'_, T> {
fn from(key: K) -> Self {
Self::_Uninitialized(key.as_ref().into())
}
}

impl<'a, T: TrieReader> MerkleKeyValueStreamState<'a, T> {
impl<T: TrieReader> MerkleKeyValueStreamState<'_, T> {
/// Returns a new iterator that will iterate over all the key-value pairs in `merkle`.
fn _new() -> Self {
Self::_Uninitialized(Box::new([]))
Expand All @@ -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<T: TrieReader> FusedStream for MerkleKeyValueStream<'_, T> {
fn is_terminated(&self) -> bool {
matches!(&self.state, MerkleKeyValueStreamState::Initialized { node_iter } if node_iter.is_terminated())
}
Expand All @@ -317,7 +317,7 @@ impl<'a, T: TrieReader> MerkleKeyValueStream<'a, T> {
}
}

impl<'a, T: TrieReader> Stream for MerkleKeyValueStream<'a, T> {
impl<T: TrieReader> Stream for MerkleKeyValueStream<'_, T> {
type Item = Result<(Key, Value), api::Error>;

fn poll_next(
Expand Down Expand Up @@ -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<T: TrieReader> Iterator for PathIterator<'_, '_, T> {
type Item = Result<PathIterItem, MerkleError>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
11 changes: 0 additions & 11 deletions firewood/src/v2/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbError> for api::Error {
fn from(value: DbError) -> Self {
match value {
Expand Down
5 changes: 4 additions & 1 deletion firewood/src/v2/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ impl<T> Proposal<T> {
#[async_trait]
impl<T: api::DbView + Send + Sync> api::DbView for Proposal<T> {
// TODO: Replace with the correct stream type for an in-memory proposal implementation
type Stream<'a> = Empty<Result<(Box<[u8]>, Vec<u8>), api::Error>> where T: 'a;
type Stream<'a>
= Empty<Result<(Box<[u8]>, Vec<u8>), api::Error>>
where
T: 'a;

async fn root_hash(&self) -> Result<Option<api::HashKey>, api::Error> {
todo!();
Expand Down
2 changes: 1 addition & 1 deletion fwdctl/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ fn u8_to_string(data: &[u8]) -> Cow<'_, str> {
}

fn key_parser(s: &str) -> Result<Box<[u8]>, std::io::Error> {
return Ok(Box::from(s.as_bytes()));
Ok(Box::from(s.as_bytes()))
}
1 change: 0 additions & 1 deletion storage/src/linear/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Read>, Error>;

/// Return the size of the underlying storage, in bytes
Expand Down
1 change: 0 additions & 1 deletion storage/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ pub struct PathIterItem {
}

#[cfg(test)]

mod test {
use crate::{
node::{BranchNode, LeafNode, Node},
Expand Down
6 changes: 3 additions & 3 deletions storage/src/node/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<'a> NibblesIterator<'a> {
}
}

impl<'a> DoubleEndedIterator for NibblesIterator<'a> {
impl DoubleEndedIterator for NibblesIterator<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.is_empty() {
return None;
Expand Down
2 changes: 0 additions & 2 deletions storage/src/nodestore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ fn area_size_to_index(n: u64) -> Result<AreaIndex, Error> {
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<T, U> {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/src/trie_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 29d0d3d

Please sign in to comment.