add cargo clippy to CI

This commit is contained in:
Dustin J. Mitchell
2020-11-24 12:44:32 -05:00
parent 2232aa8083
commit ca70d2c914
12 changed files with 98 additions and 93 deletions

View File

@@ -1,3 +1,5 @@
#![allow(clippy::new_without_default)]
use crate::taskstorage::{Operation, TaskMap, TaskStorage, TaskStorageTxn};
use failure::{format_err, Fallible};
use std::collections::hash_map::Entry;
@@ -48,7 +50,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
fn create_task(&mut self, uuid: Uuid) -> Fallible<bool> {
if let ent @ Entry::Vacant(_) = self.mut_data_ref().tasks.entry(uuid) {
ent.or_insert(TaskMap::new());
ent.or_insert_with(TaskMap::new);
Ok(true)
} else {
Ok(false)
@@ -61,11 +63,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
}
fn delete_task(&mut self, uuid: &Uuid) -> Fallible<bool> {
if let Some(_) = self.mut_data_ref().tasks.remove(uuid) {
Ok(true)
} else {
Ok(false)
}
Ok(self.mut_data_ref().tasks.remove(uuid).is_some())
}
fn all_tasks<'a>(&mut self) -> Fallible<Vec<(Uuid, TaskMap)>> {
@@ -73,12 +71,12 @@ impl<'t> TaskStorageTxn for Txn<'t> {
.data_ref()
.tasks
.iter()
.map(|(u, t)| (u.clone(), t.clone()))
.map(|(u, t)| (*u, t.clone()))
.collect())
}
fn all_task_uuids<'a>(&mut self) -> Fallible<Vec<Uuid>> {
Ok(self.data_ref().tasks.keys().map(|u| u.clone()).collect())
Ok(self.data_ref().tasks.keys().copied().collect())
}
fn base_version(&mut self) -> Fallible<u64> {
@@ -110,7 +108,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
fn add_to_working_set(&mut self, uuid: &Uuid) -> Fallible<usize> {
let working_set = &mut self.mut_data_ref().working_set;
working_set.push(Some(uuid.clone()));
working_set.push(Some(*uuid));
Ok(working_set.len())
}

View File

@@ -13,21 +13,20 @@ struct Key(uuid::Bytes);
impl From<&[u8]> for Key {
fn from(bytes: &[u8]) -> Key {
let key = Key(bytes.try_into().unwrap());
key
Key(bytes.try_into().unwrap())
}
}
impl From<&Uuid> for Key {
fn from(uuid: &Uuid) -> Key {
let key = Key(uuid.as_bytes().clone());
let key = Key(*uuid.as_bytes());
key
}
}
impl From<Uuid> for Key {
fn from(uuid: Uuid) -> Key {
let key = Key(uuid.as_bytes().clone());
let key = Key(*uuid.as_bytes());
key
}
}
@@ -108,7 +107,7 @@ struct Txn<'t> {
impl<'t> Txn<'t> {
// get the underlying kv Txn
fn kvtxn<'a>(&mut self) -> &mut kv::Txn<'t> {
fn kvtxn(&mut self) -> &mut kv::Txn<'t> {
if let Some(ref mut txn) = self.txn {
txn
} else {
@@ -316,7 +315,7 @@ impl<'t> TaskStorageTxn for Txn<'t> {
kvtxn.set(
working_set_bucket,
next_index.into(),
Msgpack::to_value_buf(uuid.clone())?,
Msgpack::to_value_buf(*uuid)?,
)?;
kvtxn.set(
numbers_bucket,
@@ -387,7 +386,7 @@ mod test {
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
assert!(txn.create_task(uuid.clone())?);
assert!(txn.create_task(uuid)?);
txn.commit()?;
}
{
@@ -405,12 +404,12 @@ mod test {
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
assert!(txn.create_task(uuid.clone())?);
assert!(txn.create_task(uuid)?);
txn.commit()?;
}
{
let mut txn = storage.txn()?;
assert!(!txn.create_task(uuid.clone())?);
assert!(!txn.create_task(uuid)?);
txn.commit()?;
}
Ok(())
@@ -436,10 +435,7 @@ mod test {
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
txn.set_task(
uuid.clone(),
taskmap_with(vec![("k".to_string(), "v".to_string())]),
)?;
txn.set_task(uuid, taskmap_with(vec![("k".to_string(), "v".to_string())]))?;
txn.commit()?;
}
{
@@ -472,7 +468,7 @@ mod test {
let uuid = Uuid::new_v4();
{
let mut txn = storage.txn()?;
assert!(txn.create_task(uuid.clone())?);
assert!(txn.create_task(uuid)?);
txn.commit()?;
}
{

View File

@@ -52,10 +52,10 @@ pub trait TaskStorageTxn {
fn delete_task(&mut self, uuid: &Uuid) -> Fallible<bool>;
/// Get the uuids and bodies of all tasks in the storage, in undefined order.
fn all_tasks<'a>(&mut self) -> Fallible<Vec<(Uuid, TaskMap)>>;
fn all_tasks(&mut self) -> Fallible<Vec<(Uuid, TaskMap)>>;
/// Get the uuids of all tasks in the storage, in undefined order.
fn all_task_uuids<'a>(&mut self) -> Fallible<Vec<Uuid>>;
fn all_task_uuids(&mut self) -> Fallible<Vec<Uuid>>;
/// Get the current base_version for this storage -- the last version synced from the server.
fn base_version(&mut self) -> Fallible<u64>;
@@ -65,7 +65,7 @@ pub trait TaskStorageTxn {
/// Get the current set of outstanding operations (operations that have not been sync'd to the
/// server yet)
fn operations<'a>(&mut self) -> Fallible<Vec<Operation>>;
fn operations(&mut self) -> Fallible<Vec<Operation>>;
/// Add an operation to the end of the list of operations in the storage. Note that this
/// merely *stores* the operation; it is up to the TaskDB to apply it.

View File

@@ -109,12 +109,9 @@ impl Operation {
} else if timestamp1 < timestamp2 {
// prefer the later modification
(None, Some(operation2))
} else if timestamp1 > timestamp2 {
// prefer the later modification
//(Some(operation1), None)
(Some(operation1), None)
} else {
// arbitrarily resolve in favor of the first operation
// prefer the later modification or, if the modifications are the same,
// just choose one of them
(Some(operation1), None)
}
}