Skip to content

Commit

Permalink
ci: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 24, 2024
1 parent 3362606 commit 019602e
Show file tree
Hide file tree
Showing 23 changed files with 226 additions and 100 deletions.
53 changes: 53 additions & 0 deletions async-skipdb/examples/optimistic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_return)]

use async_skipdb::optimistic::TokioOptimisticDb;

#[derive(Debug)]
Expand Down Expand Up @@ -61,6 +63,57 @@ async fn main() {
txn.commit().await.unwrap();
}

{
let alice = Person {
hobby: "swim".to_string(),
age: 20,
};
let bob = Person {
hobby: "run".to_string(),
age: 30,
};

let mut txn = db.write().await;
txn.insert("Alice".to_string(), alice).unwrap();
txn.insert("Bob".to_string(), bob).unwrap();

{
let alice = txn.get("Alice").unwrap().unwrap();
assert_eq!(alice.value().age, 20);
assert_eq!(alice.value().hobby, "swim");
}

{
// output:
// Alice:Person { hobby: "swim", age: 20 }
// Bob:Person { hobby: "run", age: 30 }
for ent in txn.iter().unwrap() {
println!("{}:{:?}", ent.key(), ent.value());
}

// output:
// Bob:Person { hobby: "run", age: 30 }
// Alice:Person { hobby: "swim", age: 20 }
for ent in txn.iter_rev().unwrap() {
println!("{}:{:?}", ent.key(), ent.value());
}

// output:
// Bob:Person { hobby: "run", age: 30 }
for ent in txn.range("B".to_string()..).unwrap() {
println!("{}:{:?}", ent.key(), ent.value());
}

// output:
// Alice:Person { hobby: "swim", age: 20 }
for ent in txn.range_rev(..="B".to_string()).unwrap() {
println!("{}:{:?}", ent.key(), ent.value());
}
}

txn.commit().await.unwrap();
}

{
let txn = db.read().await;
let alice = txn.get("Alice").unwrap();
Expand Down
56 changes: 56 additions & 0 deletions async-skipdb/examples/serializable.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_return)]

use async_skipdb::serializable::TokioSerializableDb;

#[derive(Debug)]
Expand Down Expand Up @@ -65,6 +67,60 @@ async fn main() {
txn.commit().await.unwrap();
}

{
let alice = Person {
name: "Alice".to_string(),
hobby: "swim".to_string(),
age: 20,
};
let bob = Person {
name: "Bob".to_string(),
hobby: "run".to_string(),
age: 30,
};

let mut txn = db.serializable_write().await;
txn.insert(1, alice).unwrap();
txn.insert(2, bob).unwrap();

{
let alice = txn.get(&1).unwrap().unwrap();
assert_eq!(alice.value().name, "Alice");
assert_eq!(alice.value().age, 20);
assert_eq!(alice.value().hobby, "swim");
}

{
// output:
// 1: Person { name: "Alice", hobby: "swim", age: 20 }
// 2: Person { name: "Bob", hobby: "run", age: 30 }
for ent in txn.iter().unwrap() {
println!("{}: {:?}", ent.key(), ent.value());
}

// output:
// 2: Person { name: "Bob", hobby: "run", age: 30 }
// 1: Person { name: "Alice", hobby: "swim", age: 20 }
for ent in txn.iter_rev().unwrap() {
println!("{}: {:?}", ent.key(), ent.value());
}

// output:
// 2: Person { name: "Bob", hobby: "run", age: 30 }
for ent in txn.range(1..).unwrap() {
println!("{}: {:?}", ent.key(), ent.value());
}

// output:
// 1: Person { name: "Alice", hobby: "swim", age: 20 }
for ent in txn.range_rev(..2).unwrap() {
println!("{}: {:?}", ent.key(), ent.value());
}
}

txn.commit().await.unwrap();
}

{
let txn = db.read().await;
let alice = txn.get(&1).unwrap();
Expand Down
1 change: 1 addition & 0 deletions async-skipdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{borrow::Borrow, hash::BuildHasher, ops::RangeBounds, sync::Arc};
use async_txn::{error::TransactionError, AsyncRtm, AsyncTm, AsyncWtm, HashCm, HashCmOptions};

/// `OptimisticDb` implementation, which requires `K` implements both [`Hash`](core::hash::Hash) and [`Ord`].
///
/// If your `K` does not implement [`Hash`](core::hash::Hash), you can use [`SerializableDb`] instead.
pub mod optimistic;

Expand Down
2 changes: 1 addition & 1 deletion async-skipdb/src/optimistic/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blocks_in_conditions)]
#![allow(clippy::blocks_in_conditions, clippy::needless_return)]

use std::{
future::Future,
Expand Down
14 changes: 7 additions & 7 deletions async-skipdb/src/optimistic/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. If callback is provided, Badger will return immediately after checking
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit(
&mut self,
Expand Down Expand Up @@ -88,9 +88,9 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. Return immediately after checking for conflicts.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit_with_task<Fut, E, R>(
&mut self,
Expand Down
14 changes: 7 additions & 7 deletions async-skipdb/src/serializable/optimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. If callback is provided, database will return immediately after checking
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit(&mut self) -> Result<(), WtmError<Infallible, Infallible, Infallible>> {
let db = self.db.clone();
Expand Down Expand Up @@ -83,9 +83,9 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. Return immediately after checking for conflicts.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit_with_task<Fut, E, R>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion async-skipdb/src/serializable/optimistic/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blocks_in_conditions)]
#![allow(clippy::blocks_in_conditions, clippy::needless_return)]

use std::{
sync::atomic::{AtomicU32, Ordering},
Expand Down
14 changes: 7 additions & 7 deletions async-skipdb/src/serializable/serializable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. If callback is provided, database will return immediately after checking
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit(&mut self) -> Result<(), WtmError<Infallible, Infallible, Infallible>> {
let db = self.db.clone();
Expand Down Expand Up @@ -83,9 +83,9 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. Return immediately after checking for conflicts.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// If there is a conflict, an error will be returned immediately and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
#[inline]
pub async fn commit_with_task<Fut, E, R>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion async-skipdb/src/serializable/serializable/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blocks_in_conditions)]
#![allow(clippy::blocks_in_conditions, clippy::needless_return)]

use std::{
sync::atomic::{AtomicU32, Ordering},
Expand Down
14 changes: 7 additions & 7 deletions async-txn/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. If callback is provided, Badger will return immediately after checking
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
/// for conflicts. Writes to the database will happen in the background. If
/// there is a conflict, an error will be returned and the callback will not
/// run. If there are no conflicts, the callback will be called in the
/// background upon successful completion of writes or any error during write.
pub async fn commit<F, Fut, O, E>(
&mut self,
apply: F,
Expand Down Expand Up @@ -745,9 +745,9 @@ where
/// 4. Batch up all writes, write them to database.
///
/// 5. Return immediately after checking for conflicts.
/// If there is a conflict, an error will be returned immediately and the no task will be spawned
/// run. If there are no conflicts, a task will be spawned and the future will be called in the
/// background upon successful completion of writes or any error during write.
/// If there is a conflict, an error will be returned immediately and the no task will be spawned
/// run. If there are no conflicts, a task will be spawned and the future will be called in the
/// background upon successful completion of writes or any error during write.
pub async fn commit_with_task<F, Fut, CFut, E, R>(
&mut self,
apply: F,
Expand Down
18 changes: 9 additions & 9 deletions skipdb-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Entry<'a, K, V> {
version: u64,
}

impl<'a, K, V> Clone for Entry<'a, K, V> {
impl<K, V> Clone for Entry<'_, K, V> {
#[inline]
fn clone(&self) -> Self {
Self {
Expand All @@ -87,7 +87,7 @@ impl<'a, K, V> Clone for Entry<'a, K, V> {
}
}

impl<'a, K, V> Entry<'a, K, V> {
impl<K, V> Entry<'_, K, V> {
/// Get the value of the entry.
#[inline]
pub fn value(&self) -> Option<&V> {
Expand All @@ -110,26 +110,26 @@ impl<'a, K, V> Entry<'a, K, V> {
/// A reference to an entry in the write transaction.
pub struct ValueRef<'a, K, V>(Either<&'a V, Entry<'a, K, V>>);

impl<'a, K, V: core::fmt::Debug> core::fmt::Debug for ValueRef<'a, K, V> {
impl<K, V: core::fmt::Debug> core::fmt::Debug for ValueRef<'_, K, V> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::ops::Deref::deref(self).fmt(f)
}
}

impl<'a, K, V: core::fmt::Display> core::fmt::Display for ValueRef<'a, K, V> {
impl<K, V: core::fmt::Display> core::fmt::Display for ValueRef<'_, K, V> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::ops::Deref::deref(self).fmt(f)
}
}

impl<'a, K, V> Clone for ValueRef<'a, K, V> {
impl<K, V> Clone for ValueRef<'_, K, V> {
#[inline]
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

impl<'a, K, V> core::ops::Deref for ValueRef<'a, K, V> {
impl<K, V> core::ops::Deref for ValueRef<'_, K, V> {
type Target = V;

#[inline]
Expand All @@ -143,15 +143,15 @@ impl<'a, K, V> core::ops::Deref for ValueRef<'a, K, V> {
}
}

impl<'a, K, V> ValueRef<'a, K, V> {
impl<K, V> ValueRef<'_, K, V> {
/// Returns `true` if the value was commited.
#[inline]
pub const fn is_committed(&self) -> bool {
matches!(self.0, Either::Right(_))
}
}

impl<'a, K, V> PartialEq<V> for ValueRef<'a, K, V>
impl<K, V> PartialEq<V> for ValueRef<'_, K, V>
where
V: PartialEq,
{
Expand All @@ -161,7 +161,7 @@ where
}
}

impl<'a, K, V> PartialEq<&V> for ValueRef<'a, K, V>
impl<K, V> PartialEq<&V> for ValueRef<'_, K, V>
where
V: PartialEq,
{
Expand Down
Loading

0 comments on commit 019602e

Please sign in to comment.