mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Port common, and most of crypto, to a more aggressive clippy
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use core::fmt::Debug;
|
||||
extern crate alloc;
|
||||
use alloc::sync::Arc;
|
||||
use std::{
|
||||
sync::{Arc, RwLock},
|
||||
sync::RwLock,
|
||||
collections::{HashSet, HashMap},
|
||||
};
|
||||
|
||||
@@ -23,7 +25,7 @@ pub trait Db: 'static + Send + Sync + Clone + Debug + Get {
|
||||
fn key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let db_len = u8::try_from(db_dst.len()).unwrap();
|
||||
let dst_len = u8::try_from(item_dst.len()).unwrap();
|
||||
[[db_len].as_ref(), db_dst, [dst_len].as_ref(), item_dst, key.as_ref()].concat().to_vec()
|
||||
[[db_len].as_ref(), db_dst, [dst_len].as_ref(), item_dst, key.as_ref()].concat()
|
||||
}
|
||||
fn txn(&mut self) -> Self::Transaction<'_>;
|
||||
}
|
||||
@@ -38,7 +40,7 @@ impl<'a> Get for MemDbTxn<'a> {
|
||||
if self.2.contains(key.as_ref()) {
|
||||
return None;
|
||||
}
|
||||
self.1.get(key.as_ref()).cloned().or(self.0 .0.read().unwrap().get(key.as_ref()).cloned())
|
||||
self.1.get(key.as_ref()).cloned().or_else(|| self.0 .0.read().unwrap().get(key.as_ref()).cloned())
|
||||
}
|
||||
}
|
||||
impl<'a> DbTxn for MemDbTxn<'a> {
|
||||
@@ -66,22 +68,23 @@ impl<'a> DbTxn for MemDbTxn<'a> {
|
||||
pub struct MemDb(Arc<RwLock<HashMap<Vec<u8>, Vec<u8>>>>);
|
||||
|
||||
impl PartialEq for MemDb {
|
||||
fn eq(&self, other: &MemDb) -> bool {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
*self.0.read().unwrap() == *other.0.read().unwrap()
|
||||
}
|
||||
}
|
||||
impl Eq for MemDb {}
|
||||
|
||||
impl Default for MemDb {
|
||||
fn default() -> MemDb {
|
||||
MemDb(Arc::new(RwLock::new(HashMap::new())))
|
||||
fn default() -> Self {
|
||||
Self(Arc::new(RwLock::new(HashMap::new())))
|
||||
}
|
||||
}
|
||||
|
||||
impl MemDb {
|
||||
/// Create a new in-memory database.
|
||||
pub fn new() -> MemDb {
|
||||
MemDb::default()
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user