Skip to content

Commit

Permalink
address some clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fominok committed Dec 27, 2024
1 parent faeed02 commit f9218dc
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion grovedb/src/operations/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl GroveDb {

let tx = TxRef::new(&self.db, transaction);
let mut cost = OperationCost::default();
let merk_cache = MerkCache::new(&self, tx.as_ref(), grove_version);
let merk_cache = MerkCache::new(self, tx.as_ref(), grove_version);

cost_return_on_error!(
&mut cost,
Expand Down
4 changes: 2 additions & 2 deletions grovedb/src/reference_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ fn display_path(path: &[Vec<u8>]) -> String {
.map(|bytes| {
let mut hx = hex::encode(bytes);
if let Ok(s) = String::from_utf8(bytes.clone()) {
hx.push_str("(");
hx.push('(');
hx.push_str(&s);
hx.push_str(")");
hx.push(')');
}

hx
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a, 'db> TxRef<'a, 'db> {
}
}

impl<'a, 'db> AsRef<Transaction<'db>> for TxRef<'a, 'db> {
impl<'db> AsRef<Transaction<'db>> for TxRef<'_, 'db> {
fn as_ref(&self) -> &Transaction<'db> {
match self {
TxRef::Owned(tx) => tx,
Expand Down
4 changes: 2 additions & 2 deletions merk/src/merk/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Error;

impl<'db, S: StorageContext<'db>> Merk<S> {
/// Get metadata for the Merk under `key`.
pub fn get_meta<'s>(&'s mut self, key: Vec<u8>) -> CostResult<Option<&'s [u8]>, Error> {
pub fn get_meta(&mut self, key: Vec<u8>) -> CostResult<Option<&[u8]>, Error> {
match self.meta_cache.entry(key) {
Entry::Occupied(e) => Ok(e.into_mut().as_deref()).wrap_with_cost(Default::default()),
Entry::Vacant(e) => self
Expand All @@ -34,7 +34,7 @@ impl<'db, S: StorageContext<'db>> Merk<S> {
/// Delete metadata under `key`.
pub fn delete_meta(&mut self, key: &[u8]) -> CostResult<(), Error> {
self.storage
.delete_meta(&key, None)
.delete_meta(key, None)
.map_ok(|_| {
self.meta_cache.remove(key);
})
Expand Down
2 changes: 1 addition & 1 deletion merk/src/merk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a, I: RawIterator> KVIterator<'a, I> {
}

// Cannot be an Iterator as it should return cost
impl<'a, I: RawIterator> KVIterator<'a, I> {
impl<I: RawIterator> KVIterator<'_, I> {
/// Next key-value
pub fn next_kv(&mut self) -> CostContext<Option<(Vec<u8>, Vec<u8>)>> {
let mut cost = OperationCost::default();
Expand Down
18 changes: 9 additions & 9 deletions path/src/subtree_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct SubtreePath<'b, B> {
pub(crate) ref_variant: SubtreePathInner<'b, B>,
}

impl<'b, B: AsRef<[u8]>> Display for SubtreePath<'b, B> {
impl<B: AsRef<[u8]>> Display for SubtreePath<'_, B> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let path = self.to_vec();

Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) enum SubtreePathInner<'b, B> {
SubtreePathIter(SubtreePathIter<'b, B>),
}

impl<'bl, 'br, BL, BR> PartialEq<SubtreePath<'br, BR>> for SubtreePath<'bl, BL>
impl<'br, BL, BR> PartialEq<SubtreePath<'br, BR>> for SubtreePath<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -115,7 +115,7 @@ where
/// can guarantee is to be free of false equality; however, seemingly unrelated
/// subtrees can come one after another if they share the same length, which was
/// (not) done for performance reasons.
impl<'bl, 'br, BL, BR> PartialOrd<SubtreePath<'br, BR>> for SubtreePath<'bl, BL>
impl<'br, BL, BR> PartialOrd<SubtreePath<'br, BR>> for SubtreePath<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -134,7 +134,7 @@ where
}
}

impl<'bl, 'br, BL, BR> PartialOrd<SubtreePathBuilder<'br, BR>> for SubtreePathBuilder<'bl, BL>
impl<'br, BL, BR> PartialOrd<SubtreePathBuilder<'br, BR>> for SubtreePathBuilder<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -153,7 +153,7 @@ where
}
}

impl<'bl, 'br, BL, BR> PartialOrd<SubtreePathBuilder<'br, BR>> for SubtreePath<'bl, BL>
impl<'br, BL, BR> PartialOrd<SubtreePathBuilder<'br, BR>> for SubtreePath<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -163,7 +163,7 @@ where
}
}

impl<'bl, BL> Ord for SubtreePath<'bl, BL>
impl<BL> Ord for SubtreePath<'_, BL>
where
BL: AsRef<[u8]>,
{
Expand All @@ -172,7 +172,7 @@ where
}
}

impl<'bl, BL> Ord for SubtreePathBuilder<'bl, BL>
impl<BL> Ord for SubtreePathBuilder<'_, BL>
where
BL: AsRef<[u8]>,
{
Expand All @@ -181,7 +181,7 @@ where
}
}

impl<'b, B: AsRef<[u8]>> Eq for SubtreePath<'b, B> {}
impl<B: AsRef<[u8]>> Eq for SubtreePath<'_, B> {}

impl<'b, B> From<SubtreePathInner<'b, B>> for SubtreePath<'b, B> {
fn from(ref_variant: SubtreePathInner<'b, B>) -> Self {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'s, 'b, B> From<&'s SubtreePathBuilder<'b, B>> for SubtreePath<'s, B> {

/// Hash order is the same as iteration order: from most deep path segment up to
/// root.
impl<'b, B: AsRef<[u8]>> Hash for SubtreePath<'b, B> {
impl<B: AsRef<[u8]>> Hash for SubtreePath<'_, B> {
fn hash<H: Hasher>(&self, state: &mut H) {
match &self.ref_variant {
SubtreePathInner::Slice(slice) => slice
Expand Down
23 changes: 12 additions & 11 deletions path/src/subtree_path_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct SubtreePathBuilder<'b, B> {
pub(crate) relative: SubtreePathRelative<'b>,
}

impl<'b, B> Clone for SubtreePathBuilder<'b, B> {
impl<B> Clone for SubtreePathBuilder<'_, B> {
fn clone(&self) -> Self {
SubtreePathBuilder {
base: self.base.clone(),
Expand All @@ -57,14 +57,14 @@ impl<'b, B> Clone for SubtreePathBuilder<'b, B> {

/// Hash order is the same as iteration order: from most deep path segment up to
/// root.
impl<'b, B: AsRef<[u8]>> Hash for SubtreePathBuilder<'b, B> {
impl<B: AsRef<[u8]>> Hash for SubtreePathBuilder<'_, B> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.relative.hash(state);
self.base.hash(state);
}
}

impl<'bl, 'br, BL, BR> PartialEq<SubtreePathBuilder<'br, BR>> for SubtreePathBuilder<'bl, BL>
impl<'br, BL, BR> PartialEq<SubtreePathBuilder<'br, BR>> for SubtreePathBuilder<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -74,7 +74,7 @@ where
}
}

impl<'bl, 'br, BL, BR> PartialEq<SubtreePathBuilder<'br, BR>> for SubtreePath<'bl, BL>
impl<'br, BL, BR> PartialEq<SubtreePathBuilder<'br, BR>> for SubtreePath<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -84,7 +84,7 @@ where
}
}

impl<'bl, 'br, BL, BR> PartialEq<SubtreePath<'br, BR>> for SubtreePathBuilder<'bl, BL>
impl<'br, BL, BR> PartialEq<SubtreePath<'br, BR>> for SubtreePathBuilder<'_, BL>
where
BL: AsRef<[u8]>,
BR: AsRef<[u8]>,
Expand All @@ -94,7 +94,7 @@ where
}
}

impl<'b, B: AsRef<[u8]>> Eq for SubtreePathBuilder<'b, B> {}
impl<B: AsRef<[u8]>> Eq for SubtreePathBuilder<'_, B> {}

impl<'s, 'b, B> From<&'s SubtreePath<'b, B>> for SubtreePathBuilder<'b, B> {
fn from(value: &'s SubtreePath<'b, B>) -> Self {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Default for SubtreePathBuilder<'static, [u8; 0]> {
}
}

impl<'b, B> SubtreePathBuilder<'b, B> {
impl<B> SubtreePathBuilder<'_, B> {
/// Makes an owned `SubtreePathBuilder` out of iterator.
pub fn owned_from_iter<S: AsRef<[u8]>>(iter: impl IntoIterator<Item = S>) -> Self {
let bytes = iter.into_iter().fold(CompactBytes::new(), |mut bytes, s| {
Expand All @@ -175,7 +175,7 @@ impl<'b, B> SubtreePathBuilder<'b, B> {
}

/// Create an owned version of `SubtreePathBuilder` from `SubtreePath`.
pub fn owned_from_path<'a, S: AsRef<[u8]>>(path: SubtreePath<'a, S>) -> Self {
pub fn owned_from_path<S: AsRef<[u8]>>(path: SubtreePath<S>) -> Self {
Self::owned_from_iter(path.to_vec())
}
}
Expand Down Expand Up @@ -240,9 +240,10 @@ impl<'b, B: AsRef<[u8]>> SubtreePathBuilder<'b, B> {
}
}

/// Get a derived path for a parent and a chopped segment. The lifetime of returned path is
/// constrained solely by the original slice that this whole path hierarchy is based upon, and the point
/// of derivation has no effect on it.
/// Get a derived path for a parent and a chopped segment. The lifetime of
/// returned path is constrained solely by the original slice that this
/// whole path hierarchy is based upon, and the point of derivation has
/// no effect on it.
pub fn derive_parent_owned(&self) -> Option<(SubtreePathBuilder<'b, B>, Vec<u8>)> {
match &self.relative {
SubtreePathRelative::Empty => self
Expand Down
1 change: 1 addition & 0 deletions storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ impl StorageBatch {
}
}

#[cfg(test)]
/// Returns a number of operations in the batch.
pub fn len(&self) -> usize {
let operations = self.operations.borrow();
Expand Down

0 comments on commit f9218dc

Please sign in to comment.