Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make clippy happy #3

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 162 additions & 4 deletions src/db/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,164 @@ impl<Db: KVDatabase> KVDatabase for RwLock<Db> {
self.read().unwrap().contains_key(k)
}

#[inline(always)]
fn put(&mut self, k: &[u8], v: &[u8]) -> Result<Option<Self::Item>, Self::Error> {
self.get_mut().unwrap().put(k, v)
}

#[inline(always)]
fn or_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), Self::Error> {
self.get_mut().unwrap().or_put(k, v)
}

#[inline(always)]
fn or_put_with<O: Into<Self::Item>, F: FnOnce() -> O>(
&mut self,
k: &[u8],
default: F,
) -> Result<(), Self::Error> {
self.get_mut().unwrap().or_put_with(k, default)
}

#[inline(always)]
fn put_owned<K: AsRef<[u8]> + Into<Box<[u8]>>>(
&mut self,
k: K,
v: impl Into<Self::Item>,
) -> Result<Option<Self::Item>, Self::Error> {
self.get_mut().unwrap().put_owned(k, v)
}

#[inline(always)]
fn get<K: AsRef<[u8]> + Clone>(&self, k: K) -> Result<Option<Self::Item>, Self::Error> {
self.read().unwrap().get(k)
}

#[inline(always)]
fn is_gc_supported(&self) -> bool {
self.read().unwrap().is_gc_supported()
}

#[inline(always)]
fn set_gc_enabled(&mut self, _gc_enabled: bool) {
self.get_mut().unwrap().set_gc_enabled(_gc_enabled)
}

#[inline(always)]
fn gc_enabled(&self) -> bool {
self.read().unwrap().gc_enabled()
}

#[inline(always)]
fn remove(&mut self, k: &[u8]) -> Result<(), Self::Error> {
self.get_mut().unwrap().remove(k)
}

#[inline(always)]
fn retain<F>(&mut self, f: F) -> Result<(), Self::Error>
where
F: FnMut(&[u8], &[u8]) -> bool,
{
self.get_mut().unwrap().retain(f)
}

#[inline(always)]
fn extend<T: IntoIterator<Item = (Box<[u8]>, Self::Item)>>(
&mut self,
other: T,
) -> Result<(), Self::Error> {
self.get_mut().unwrap().extend(other)
}
}

impl<Db: KVDatabase> KVDatabase for Mutex<Db> {
type Item = Db::Item;
type Error = Db::Error;

#[inline(always)]
fn contains_key(&self, k: &[u8]) -> Result<bool, Self::Error> {
self.lock().unwrap().contains_key(k)
}

#[inline(always)]
fn put(&mut self, k: &[u8], v: &[u8]) -> Result<Option<Self::Item>, Self::Error> {
self.get_mut().unwrap().put(k, v)
}

#[inline(always)]
fn or_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), Self::Error> {
self.get_mut().unwrap().or_put(k, v)
}

#[inline(always)]
fn or_put_with<O: Into<Self::Item>, F: FnOnce() -> O>(
&mut self,
k: &[u8],
default: F,
) -> Result<(), Self::Error> {
self.get_mut().unwrap().or_put_with(k, default)
}

#[inline(always)]
fn put_owned<K: AsRef<[u8]> + Into<Box<[u8]>>>(
&mut self,
k: K,
v: impl Into<Self::Item>,
) -> Result<Option<Self::Item>, Self::Error> {
self.get_mut().unwrap().put_owned(k, v)
}

#[inline(always)]
fn get<K: AsRef<[u8]> + Clone>(&self, k: K) -> Result<Option<Self::Item>, Self::Error> {
self.lock().unwrap().get(k)
}

#[inline(always)]
fn is_gc_supported(&self) -> bool {
self.lock().unwrap().is_gc_supported()
}

#[inline(always)]
fn set_gc_enabled(&mut self, gc_enabled: bool) {
self.get_mut().unwrap().set_gc_enabled(gc_enabled)
}

#[inline(always)]
fn gc_enabled(&self) -> bool {
self.lock().unwrap().gc_enabled()
}

#[inline(always)]
fn remove(&mut self, k: &[u8]) -> Result<(), Self::Error> {
self.get_mut().unwrap().remove(k)
}

#[inline(always)]
fn retain<F>(&mut self, f: F) -> Result<(), Self::Error>
where
F: FnMut(&[u8], &[u8]) -> bool,
{
self.get_mut().unwrap().retain(f)
}

#[inline(always)]
fn extend<T: IntoIterator<Item = (Box<[u8]>, Self::Item)>>(
&mut self,
other: T,
) -> Result<(), Self::Error> {
self.get_mut().unwrap().extend(other)
}
}

impl<Db: KVDatabase> KVDatabase for Arc<RwLock<Db>> {
type Item = Db::Item;
type Error = Db::Error;

#[inline(always)]
fn contains_key(&self, k: &[u8]) -> Result<bool, Self::Error> {
self.read().unwrap().contains_key(k)
}

#[inline(always)]
fn put(&mut self, k: &[u8], v: &[u8]) -> Result<Option<Self::Item>, Self::Error> {
self.write().unwrap().put(k, v)
Expand Down Expand Up @@ -82,7 +240,7 @@ impl<Db: KVDatabase> KVDatabase for RwLock<Db> {
}
}

impl<Db: KVDatabase> KVDatabase for Mutex<Db> {
impl<Db: KVDatabase> KVDatabase for Arc<Mutex<Db>> {
type Item = Db::Item;
type Error = Db::Error;

Expand Down Expand Up @@ -498,12 +656,12 @@ impl<Db: KVDatabase> KVDatabase for &mut Db {

#[inline(always)]
fn get<K: AsRef<[u8]> + Clone>(&self, k: K) -> Result<Option<Self::Item>, Self::Error> {
(&**self).get(k)
(**self).get(k)
}

#[inline(always)]
fn is_gc_supported(&self) -> bool {
(&**self).is_gc_supported()
(**self).is_gc_supported()
}

#[inline(always)]
Expand All @@ -513,7 +671,7 @@ impl<Db: KVDatabase> KVDatabase for &mut Db {

#[inline(always)]
fn gc_enabled(&self) -> bool {
(&**self).gc_enabled()
(**self).gc_enabled()
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/db/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl KVDatabase for SledDb {

#[inline]
fn contains_key(&self, k: &[u8]) -> Result<bool, Self::Error> {
Ok(self.db.contains_key(k)?)
self.db.contains_key(k)
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/scroll_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl EncodeValueBytes for U256 {

impl DecodeValueBytes for U256 {
fn decode_values_bytes(values: &[[u8; 32]]) -> Option<Self> {
values.get(0).map(|v| U256::from_be_bytes(*v))
values.first().map(|v| U256::from_be_bytes(*v))
}
}

Expand All @@ -145,9 +145,9 @@ mod tests {

let trie_account = Account::from_revm_account_with_storage_root(account, storage_root);

trie.update(address.as_ref(), trie_account).unwrap();
trie.update(address, trie_account).unwrap();

let account: Account = trie.get(address.as_ref()).unwrap();
let account = trie.get::<Account, _>(address).unwrap().unwrap();

assert_eq!(trie_account, account);
}
Expand Down
6 changes: 3 additions & 3 deletions src/trie/zktrie/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_simple() {
old_trie.try_update(&old_key, 1, v.clone()).unwrap();
old_trie.prepare_root().unwrap();

trie.raw_update(&k, v.clone(), 1).unwrap();
trie.raw_update(k, v.clone(), 1).unwrap();
trie.commit().unwrap();

assert_eq!(old_trie.root().as_ref(), trie.root.unwrap_ref().as_slice());
Expand Down Expand Up @@ -56,7 +56,7 @@ fn test_random() {
.try_update(&old_key, compression_flag, values.clone())
.unwrap();

trie.raw_update(&k, values, compression_flag).unwrap();
trie.raw_update(k, values, compression_flag).unwrap();

keys.push((k, old_key));
}
Expand Down Expand Up @@ -95,7 +95,7 @@ fn test_random() {
.iter()
.map(|n| n.value())
.collect::<Vec<Vec<u8>>>();
let mut new_proof = trie.prove(&k).unwrap();
let mut new_proof = trie.prove(k).unwrap();
new_proof.pop(); // pop the magic bytes

assert_eq!(old_proof, new_proof);
Expand Down