From b373f1ea59afda1acd2b748dc58606b47b98bbd4 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 4 Oct 2023 16:03:21 -0400 Subject: [PATCH] Resolve warnings in changeset --- changeset/Cargo.toml | 1 - changeset/src/lib.rs | 28 ++++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/changeset/Cargo.toml b/changeset/Cargo.toml index 0e02630..450fd56 100644 --- a/changeset/Cargo.toml +++ b/changeset/Cargo.toml @@ -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 diff --git a/changeset/src/lib.rs b/changeset/src/lib.rs index 40a0666..4173ad7 100644 --- a/changeset/src/lib.rs +++ b/changeset/src/lib.rs @@ -26,7 +26,7 @@ pub enum Change { NewRecord(Value), } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Changeset { delete: HashSet, update: HashMap, @@ -34,14 +34,6 @@ pub struct Changeset { } impl Changeset { - 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 From> for Vec Self { @@ -110,7 +102,7 @@ mod tests { #[test] fn it_generates_a_new_record() { - let mut set: Changeset = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = 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 = Changeset::new(); + let mut set: Changeset = Changeset::default(); let id1 = Id::new(); let id2 = Id::new(); set.update(id1.clone(), "efgh".to_owned());