Resolve warnings in changeset

This commit is contained in:
Savanni D'Gerinel 2023-10-04 16:03:21 -04:00
parent e657320b28
commit 7b6b7ec011
2 changed files with 10 additions and 19 deletions

View File

@ -3,7 +3,6 @@ name = "changeset"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0-only"
license-file = "../COPYING"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -26,7 +26,7 @@ pub enum Change<Key: Eq + Hash, Value> {
NewRecord(Value),
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Changeset<Key: Clone + Eq + Hash, Value> {
delete: HashSet<Key>,
update: HashMap<Key, Value>,
@ -34,14 +34,6 @@ pub struct Changeset<Key: Clone + Eq + Hash, Value> {
}
impl<Key: Clone + Constructable + Eq + Hash, Value> Changeset<Key, Value> {
pub fn new() -> Self {
Self {
delete: HashSet::new(),
update: HashMap::new(),
new: HashMap::new(),
}
}
pub fn add(&mut self, r: Value) -> Key {
let k = Key::new();
self.new.insert(k.clone(), r);
@ -90,7 +82,7 @@ impl<Key: Clone + Eq + Hash, Value> From<Changeset<Key, Value>> for Vec<Change<K
.into_iter()
.map(|(k, v)| Change::UpdateRecord((k, v))),
)
.chain(new.into_iter().map(|(_, v)| Change::NewRecord(v)))
.chain(new.into_values().map(|v| Change::NewRecord(v)))
.collect()
}
}
@ -100,7 +92,7 @@ mod tests {
use super::*;
use uuid::Uuid;
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash, Default)]
struct Id(Uuid);
impl Constructable for Id {
fn new() -> Self {
@ -110,7 +102,7 @@ mod tests {
#[test]
fn it_generates_a_new_record() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
set.add("efgh".to_string());
let changes = Vec::from(set.clone());
assert_eq!(changes.len(), 1);
@ -125,7 +117,7 @@ mod tests {
#[test]
fn it_generates_a_delete_record() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let id1 = Id::new();
set.delete(id1.clone());
let changes = Vec::from(set.clone());
@ -142,7 +134,7 @@ mod tests {
#[test]
fn update_unrelated_records() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let id1 = Id::new();
let id2 = Id::new();
set.update(id1.clone(), "abcd".to_owned());
@ -155,7 +147,7 @@ mod tests {
#[test]
fn delete_cancels_new() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let key = set.add("efgh".to_string());
set.delete(key);
let changes = Vec::from(set);
@ -164,7 +156,7 @@ mod tests {
#[test]
fn delete_cancels_update() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let id = Id::new();
set.update(id.clone(), "efgh".to_owned());
set.delete(id.clone());
@ -175,7 +167,7 @@ mod tests {
#[test]
fn update_atop_new_is_new() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let key = set.add("efgh".to_owned());
set.update(key, "wxyz".to_owned());
let changes = Vec::from(set);
@ -185,7 +177,7 @@ mod tests {
#[test]
fn updates_get_squashed() {
let mut set: Changeset<Id, String> = Changeset::new();
let mut set: Changeset<Id, String> = Changeset::default();
let id1 = Id::new();
let id2 = Id::new();
set.update(id1.clone(), "efgh".to_owned());