From 49ccd0baccbd088e4efe04c6a7365dff553ef74f Mon Sep 17 00:00:00 2001
From: Marc-Antoine Manningham <marc-antoine.m@outlook.com>
Date: Fri, 13 Sep 2024 23:15:26 -0400
Subject: [PATCH] refactor: trait improvement

---
 combinatoric-solver/src/collection.rs | 37 +++++++++------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/combinatoric-solver/src/collection.rs b/combinatoric-solver/src/collection.rs
index f16919c..a7c1dd9 100644
--- a/combinatoric-solver/src/collection.rs
+++ b/combinatoric-solver/src/collection.rs
@@ -1,20 +1,18 @@
-use crate::score::Score;
+use crate::{item::ItemVariant, score::Score};
 
 #[derive(Clone)]
-pub struct Collection<const MAX_ITEMS: usize, S, ItemVariant>
+pub struct Collection<const MAX_ITEMS: usize, S, V>
 where
     S: Score,
-    ItemVariant: Eq,
+    V: ItemVariant,
 {
     pub score: S,
     pub item_quantity: usize,
-    pub item_variant: [ItemVariant; MAX_ITEMS],
+    pub item_variant: [V; MAX_ITEMS],
 }
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy>
-    Collection<MAX_ITEMS, S, ItemVariant>
-{
-    pub fn push(&self, item_variant: ItemVariant) -> Self {
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Collection<MAX_ITEMS, S, V> {
+    pub fn push(&self, item_variant: V) -> Self {
         let mut new = self.clone();
         new.item_variant[self.item_quantity] = item_variant;
         new.item_quantity += 1;
@@ -22,13 +20,11 @@ impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy>
     }
 }
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> Default
-    for Collection<MAX_ITEMS, S, ItemVariant>
-{
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Default for Collection<MAX_ITEMS, S, V> {
     fn default() -> Self {
         let score = S::default();
         let item_quantity = 0;
-        let item_variant = [ItemVariant::default(); MAX_ITEMS];
+        let item_variant = [V::default(); MAX_ITEMS];
         Self {
             score,
             item_quantity,
@@ -37,30 +33,21 @@ impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq + Default + Copy> Default
     }
 }
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> PartialEq
-    for Collection<MAX_ITEMS, S, ItemVariant>
-{
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialEq for Collection<MAX_ITEMS, S, V> {
     fn eq(&self, other: &Self) -> bool {
         self.item_variant == other.item_variant
     }
 }
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> PartialOrd
-    for Collection<MAX_ITEMS, S, ItemVariant>
-{
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> PartialOrd for Collection<MAX_ITEMS, S, V> {
     fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
         self.score.partial_cmp(&other.score)
     }
 }
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> Eq
-    for Collection<MAX_ITEMS, S, ItemVariant>
-{
-}
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Eq for Collection<MAX_ITEMS, S, V> {}
 
-impl<const MAX_ITEMS: usize, S: Score, ItemVariant: Eq> Ord
-    for Collection<MAX_ITEMS, S, ItemVariant>
-{
+impl<const MAX_ITEMS: usize, S: Score, V: ItemVariant> Ord for Collection<MAX_ITEMS, S, V> {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
         self.score.cmp(&other.score)
     }
-- 
GitLab