chore: clean relative to references and borrows

- lint message: the borrowed expression implements the required traits
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrows_for_generic_args
- lint message: this expression creates a reference which is immediately dereferenced by the compiler
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#needless_borrow
- lint message: you don't need to add `&` to all patterns
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#match_ref_pat
- remove useless taken reference
lint message: needlessly taken reference of left operand
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#op_ref
- use &Path instead of &PathBuf as fn parameters
lint message: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#ptr_arg
This commit is contained in:
Gwen Lg
2025-12-13 17:43:05 +01:00
parent 209263eb93
commit 141b3f24f1
35 changed files with 129 additions and 134 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
use core::ops::Bound;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
@@ -20,7 +20,7 @@ pub use fjall;
// --
pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
pub(crate) fn open_db(path: &Path, opt: &OpenOpt) -> Result<Db> {
info!("Opening Fjall database at: {}", path.display());
if opt.fsync {
return Err(Error(
@@ -109,11 +109,11 @@ impl IDb for FjallDb {
.keyspace
.list_partitions()
.iter()
.map(|n| decode_name(&n))
.map(|n| decode_name(n))
.collect::<Result<Vec<_>>>()?)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Fjall.db_path(base_path);
@@ -325,7 +325,7 @@ impl<'a> ITx for FjallTx<'a> {
let high = clone_bound(high);
Ok(Box::new(
self.tx
.range::<Vec<u8>, ByteVecRangeBounds>(&tree, (low, high))
.range::<Vec<u8>, ByteVecRangeBounds>(tree, (low, high))
.map(iterator_remap_tx),
))
}
@@ -340,7 +340,7 @@ impl<'a> ITx for FjallTx<'a> {
let high = clone_bound(high);
Ok(Box::new(
self.tx
.range::<Vec<u8>, ByteVecRangeBounds>(&tree, (low, high))
.range::<Vec<u8>, ByteVecRangeBounds>(tree, (low, high))
.rev()
.map(iterator_remap_tx),
))
+3 -3
View File
@@ -17,7 +17,7 @@ use core::ops::{Bound, RangeBounds};
use std::borrow::Cow;
use std::cell::Cell;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use thiserror::Error;
@@ -147,7 +147,7 @@ impl Db {
}
}
pub fn snapshot(&self, path: &PathBuf) -> Result<()> {
pub fn snapshot(&self, path: &Path) -> Result<()> {
self.0.snapshot(path)
}
@@ -348,7 +348,7 @@ pub(crate) trait IDb: Send + Sync {
fn engine(&self) -> String;
fn open_tree(&self, name: &str) -> Result<usize>;
fn list_trees(&self) -> Result<Vec<String>>;
fn snapshot(&self, path: &PathBuf) -> Result<()>;
fn snapshot(&self, path: &Path) -> Result<()>;
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value>>;
fn approximate_len(&self, tree: usize) -> Result<usize>;
+5 -5
View File
@@ -3,7 +3,7 @@ use core::ops::Bound;
use std::collections::HashMap;
use std::convert::TryInto;
use std::marker::PhantomPinned;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::sync::{Arc, RwLock};
@@ -22,7 +22,7 @@ pub use heed;
pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
info!("Opening LMDB database at: {}", path.display());
if let Err(e) = std::fs::create_dir_all(&path) {
if let Err(e) = std::fs::create_dir_all(path) {
return Err(Error(
format!("Unable to create LMDB data directory: {}", e).into(),
));
@@ -44,7 +44,7 @@ pub(crate) fn open_db(path: &PathBuf, opt: &OpenOpt) -> Result<Db> {
env_builder.flag(heed::flags::Flags::MdbNoSync);
}
}
match env_builder.open(&path) {
match env_builder.open(path) {
Err(heed::Error::Io(e)) if e.kind() == std::io::ErrorKind::OutOfMemory => {
return Err(Error(
"OutOfMemory error while trying to open LMDB database. This can happen \
@@ -147,7 +147,7 @@ impl IDb for LmdbDb {
Ok(ret2)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Lmdb.db_path(base_path);
self.db
@@ -399,7 +399,7 @@ where
// before the tx it is pointing to.
unsafe { &*&raw const *tx }
};
let iter = iterfun(&tx_lifetime_overextended)?;
let iter = iterfun(tx_lifetime_overextended)?;
*boxed.as_mut().iter() = Some(iter);
+3 -3
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use crate::{Db, Error, Result};
@@ -25,8 +25,8 @@ impl Engine {
}
/// Return engine-specific DB path from base path
pub fn db_path(&self, base_path: &PathBuf) -> PathBuf {
let mut ret = base_path.clone();
pub fn db_path(&self, base_path: &Path) -> PathBuf {
let mut ret = base_path.to_path_buf();
match self {
Self::Lmdb => {
ret.push("db.lmdb");
+4 -4
View File
@@ -1,7 +1,7 @@
use core::ops::Bound;
use std::marker::PhantomPinned;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex, RwLock};
@@ -110,7 +110,7 @@ impl IDb for SqliteDb {
let name = format!("tree_{}", name.replace(':', "_COLON_"));
let mut trees = self.trees.write().unwrap();
if let Some(i) = trees.iter().position(|x| x.as_ref() == &name) {
if let Some(i) = trees.iter().position(|x| x.as_ref() == name) {
Ok(i)
} else {
let db = self.db.get()?;
@@ -150,10 +150,10 @@ impl IDb for SqliteDb {
Ok(trees)
}
fn snapshot(&self, base_path: &PathBuf) -> Result<()> {
fn snapshot(&self, base_path: &Path) -> Result<()> {
std::fs::create_dir_all(base_path)?;
let path = Engine::Sqlite
.db_path(&base_path)
.db_path(base_path)
.into_os_string()
.into_string()
.map_err(|_| Error("invalid sqlite path string".into()))?;