Address new clippy warnings

without.crypto
Jan-Erik Rediger 2 years ago committed by Kagami Sascha Rosylight
parent 4410a95b41
commit a2de8a917d
  1. 24
      src/backend/impl_lmdb/arch_migrator.rs
  2. 4
      src/backend/impl_safe/environment.rs
  3. 2
      src/backend/impl_safe/snapshot.rs
  4. 23
      src/backend/impl_safe/transaction.rs
  5. 4
      src/env.rs
  6. 1
      src/lib.rs
  7. 4
      src/manager.rs
  8. 2
      src/value.rs

@ -7,6 +7,8 @@
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#![allow(dead_code)] // TODO: Get rid of unused struct members
#![allow(clippy::upper_case_acronyms)] // TODO: Consider renaming things like `BRANCH`
//! A utility for migrating data from one LMDB environment to another. Notably, this tool
//! can migrate data from an enviroment created with a different bit-depth than the
@ -333,7 +335,7 @@ impl Page {
}
}
fn parse_meta_data(mut cursor: &mut Cursor<&[u8]>, bits: Bits) -> MigrateResult<MetaData> {
fn parse_meta_data(cursor: &mut Cursor<&[u8]>, bits: Bits) -> MigrateResult<MetaData> {
cursor.seek(SeekFrom::Start(page_header_size(bits)))?;
Ok(MetaData {
@ -342,8 +344,8 @@ impl Page {
mm_address: cursor.read_uint::<LittleEndian>(bits.size())?,
mm_mapsize: cursor.read_uint::<LittleEndian>(bits.size())?,
mm_dbs: Databases {
free: Database::new(&mut cursor, bits)?,
main: Database::new(&mut cursor, bits)?,
free: Database::new(cursor, bits)?,
main: Database::new(cursor, bits)?,
},
mm_last_pg: cursor.read_uint::<LittleEndian>(bits.size())?,
mm_txnid: cursor.read_uint::<LittleEndian>(bits.size())?,
@ -614,7 +616,7 @@ impl Migrator {
// awaiting completion of an existing one.
env.create_db(None, meta_data.mm_dbs.main.md_flags)?;
for (subdb_name, subdb_info) in &subdbs {
env.create_db(Some(str::from_utf8(&subdb_name)?), subdb_info.md_flags)?;
env.create_db(Some(str::from_utf8(subdb_name)?), subdb_info.md_flags)?;
}
// Now open the read-write transaction that we'll use to migrate all the data.
@ -633,7 +635,7 @@ impl Migrator {
for (subdb_name, subdb_info) in &subdbs {
let root_page = Rc::new(self.get_page(subdb_info.md_root)?);
let pairs = self.get_pairs(root_page)?;
let db = env.open_db(Some(str::from_utf8(&subdb_name)?))?;
let db = env.open_db(Some(str::from_utf8(subdb_name)?))?;
for (key, value) in pairs {
// If we knew that the target database was empty, we could specify
// WriteFlags::APPEND to speed up the migration.
@ -916,7 +918,7 @@ mod tests {
migrator.migrate(new_env.path())?;
// Dump data from the new env to a new dump file.
let mut migrator = Migrator::new(&new_env.path())?;
let mut migrator = Migrator::new(new_env.path())?;
let mut new_dump_file = tempfile()?;
migrator.dump(Some("subdb"), &new_dump_file)?;
@ -942,7 +944,7 @@ mod tests {
migrator.migrate(new_env.path())?;
// Dump data from the new env to a new dump file.
let mut migrator = Migrator::new(&new_env.path())?;
let mut migrator = Migrator::new(new_env.path())?;
let mut new_dump_file = tempfile()?;
migrator.dump(Some("subdb"), &new_dump_file)?;
@ -974,7 +976,7 @@ mod tests {
// Confirm that it isn't possible to open the old environment with LMDB.
assert_eq!(
match Environment::new().open(&old_env.path()) {
match Environment::new().open(old_env.path()) {
Err(err) => err,
_ => panic!("opening the environment should have failed"),
},
@ -983,11 +985,11 @@ mod tests {
// Migrate data from the old env to a new one.
let new_env = tempdir()?;
let mut migrator = Migrator::new(&old_env.path())?;
let mut migrator = Migrator::new(old_env.path())?;
migrator.migrate(new_env.path())?;
// Dump data from the new env to a new dump file.
let mut migrator = Migrator::new(&new_env.path())?;
let mut migrator = Migrator::new(new_env.path())?;
let mut new_dump_file = tempfile()?;
migrator.dump(Some("subdb"), &new_dump_file)?;
@ -1002,7 +1004,7 @@ mod tests {
// possible to open the old env with LMDB.
fs::copy(new_env.path().join("data.mdb"), old_env.path().join("data.mdb"))?;
fs::copy(new_env.path().join("lock.mdb"), old_env.path().join("lock.mdb"))?;
assert!(Environment::new().open(&old_env.path()).is_ok());
assert!(Environment::new().open(old_env.path()).is_ok());
Ok(())
}

@ -163,7 +163,7 @@ impl EnvironmentImpl {
fn deserialize(bytes: &[u8], discard_if_corrupted: bool) -> Result<(DatabaseArena, DatabaseNameMap), ErrorImpl> {
let mut arena = DatabaseArena::new();
let mut name_map = HashMap::new();
let data: HashMap<_, _> = match bincode::deserialize(&bytes) {
let data: HashMap<_, _> = match bincode::deserialize(bytes) {
Err(_) if discard_if_corrupted => Ok(HashMap::new()),
result => result,
}?;
@ -320,6 +320,6 @@ impl<'e> BackendEnvironment<'e> for EnvironmentImpl {
// they're both currently unimplemented with this storage backend.
let mut db_filename = self.path.clone();
db_filename.push(DEFAULT_DB_FILENAME);
return vec![db_filename];
vec![db_filename]
}
}

@ -38,7 +38,7 @@ pub struct Snapshot {
impl Snapshot {
pub(crate) fn new(flags: Option<DatabaseFlagsImpl>) -> Snapshot {
Snapshot {
flags: flags.unwrap_or_else(DatabaseFlagsImpl::default),
flags: flags.unwrap_or_default(),
map: Default::default(),
}
}

@ -7,6 +7,7 @@
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#![allow(dead_code)] // TODO: Get rid of unused struct members
use std::{
collections::HashMap,
@ -51,8 +52,8 @@ impl<'t> BackendRoTransaction for RoTransactionImpl<'t> {
type Error = ErrorImpl;
fn get(&self, db: &Self::Database, key: &[u8]) -> Result<&[u8], Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
snapshot.get(key).ok_or_else(|| ErrorImpl::KeyValuePairNotFound)
let snapshot = self.snapshots.get(db).ok_or(ErrorImpl::DbIsForeignError)?;
snapshot.get(key).ok_or(ErrorImpl::KeyValuePairNotFound)
}
fn abort(self) {
@ -64,7 +65,7 @@ impl<'t> BackendRoCursorTransaction<'t> for RoTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let snapshot = self.snapshots.get(db).ok_or(ErrorImpl::DbIsForeignError)?;
Ok(RoCursorImpl(snapshot))
}
}
@ -93,8 +94,8 @@ impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
type Flags = WriteFlagsImpl;
fn get(&self, db: &Self::Database, key: &[u8]) -> Result<&[u8], Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
snapshot.get(key).ok_or_else(|| ErrorImpl::KeyValuePairNotFound)
let snapshot = self.snapshots.get(db).ok_or(ErrorImpl::DbIsForeignError)?;
snapshot.get(key).ok_or(ErrorImpl::KeyValuePairNotFound)
}
#[cfg(not(feature = "db-dup-sort"))]
@ -107,7 +108,7 @@ impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
#[cfg(feature = "db-dup-sort")]
fn put(&mut self, db: &Self::Database, key: &[u8], value: &[u8], _flags: Self::Flags) -> Result<(), Self::Error> {
use super::DatabaseFlagsImpl;
let snapshot = self.snapshots.get_mut(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let snapshot = self.snapshots.get_mut(db).ok_or(ErrorImpl::DbIsForeignError)?;
if snapshot.flags().contains(DatabaseFlagsImpl::DUP_SORT) {
snapshot.put_dup(key, value);
} else {
@ -126,16 +127,16 @@ impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
#[cfg(feature = "db-dup-sort")]
fn del(&mut self, db: &Self::Database, key: &[u8], value: Option<&[u8]>) -> Result<(), Self::Error> {
use super::DatabaseFlagsImpl;
let snapshot = self.snapshots.get_mut(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let snapshot = self.snapshots.get_mut(db).ok_or(ErrorImpl::DbIsForeignError)?;
let deleted = match (value, snapshot.flags()) {
(Some(value), flags) if flags.contains(DatabaseFlagsImpl::DUP_SORT) => snapshot.del_exact(key, value),
_ => snapshot.del(key),
};
Ok(deleted.ok_or_else(|| ErrorImpl::KeyValuePairNotFound)?)
deleted.ok_or(ErrorImpl::KeyValuePairNotFound)
}
fn clear_db(&mut self, db: &Self::Database) -> Result<(), Self::Error> {
let snapshot = self.snapshots.get_mut(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let snapshot = self.snapshots.get_mut(db).ok_or(ErrorImpl::DbIsForeignError)?;
snapshot.clear();
Ok(())
}
@ -144,7 +145,7 @@ impl<'t> BackendRwTransaction for RwTransactionImpl<'t> {
let mut dbs = self.env.dbs_mut()?;
for (id, snapshot) in self.snapshots {
let db = dbs.arena.get_mut(id.0).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let db = dbs.arena.get_mut(id.0).ok_or(ErrorImpl::DbIsForeignError)?;
db.replace(snapshot);
}
@ -161,7 +162,7 @@ impl<'t> BackendRwCursorTransaction<'t> for RwTransactionImpl<'t> {
type RoCursor = RoCursorImpl<'t>;
fn open_ro_cursor(&'t self, db: &Self::Database) -> Result<Self::RoCursor, Self::Error> {
let snapshot = self.snapshots.get(db).ok_or_else(|| ErrorImpl::DbIsForeignError)?;
let snapshot = self.snapshots.get(db).ok_or(ErrorImpl::DbIsForeignError)?;
Ok(RoCursorImpl(snapshot))
}
}

@ -61,7 +61,7 @@ pub static DEFAULT_MAX_DBS: c_uint = 5;
/// Wrapper around an `Environment` (e.g. such as an `LMDB` or `SafeMode` environment).
#[derive(Debug)]
pub struct Rkv<E> {
path: PathBuf,
_path: PathBuf,
env: E,
}
@ -104,7 +104,7 @@ where
B: BackendEnvironmentBuilder<'e, Environment = E>,
{
Ok(Rkv {
path: path.into(),
_path: path.into(),
env: builder.open(path).map_err(|e| e.into())?,
})
}

@ -7,6 +7,7 @@
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#![allow(clippy::from_over_into)] // TODO: `Into` implementations in [safe/lmdb]/flags.rs
//! A simple, humane, typed key-value storage solution. It supports multiple backend
//! engines with varying guarantees, such as [LMDB](http://www.lmdb.tech/doc/) for

@ -182,13 +182,13 @@ where
#[cfg(feature = "lmdb")]
impl Manager<LmdbEnvironment> {
pub fn singleton() -> &'static RwLock<Manager<LmdbEnvironment>> {
&*MANAGER_LMDB
&MANAGER_LMDB
}
}
impl Manager<SafeModeEnvironment> {
pub fn singleton() -> &'static RwLock<Manager<SafeModeEnvironment>> {
&*MANAGER_SAFE_MODE
&MANAGER_SAFE_MODE
}
}

@ -44,7 +44,7 @@ pub enum Type {
/// We use manual tagging, because <https://github.com/serde-rs/serde/issues/610>.
impl Type {
pub fn from_tag(tag: u8) -> Result<Type, DataError> {
Type::from_primitive(tag).ok_or_else(|| DataError::UnknownType(tag))
Type::from_primitive(tag).ok_or(DataError::UnknownType(tag))
}
#[allow(clippy::wrong_self_convention)]

Loading…
Cancel
Save