src/card.rs
changeset 5 0dd7f2c9fd81
parent 4 a2f0cb2b5c13
--- a/src/card.rs	Tue Jan 31 23:25:50 2023 +0100
+++ b/src/card.rs	Sat Feb 04 22:46:13 2023 +0100
@@ -1,13 +1,20 @@
 use core::fmt;
 
-/*** Card ****/
+/// This is the implementation of a Card. 
+/// Smart card! ;-) Can do a few things by herself.
+
 #[derive(Debug)]
+/// A playing Card. Knows its face `value` 
+/// and the punishment `points` (in the game 
+/// these are symbolised by little bull heads).
 pub struct Card {
     pub value: i8,
     pub points: i8,
 }
 
 impl Card {
+    /// Generate a new card with the face `value` parameter.
+    /// Calculates the `points` for the value.
     pub fn new(value: i8)->Self {
 
         let mut points = 0;
@@ -24,15 +31,17 @@
         }
 
         if value % 10 == value / 10 {
-            // same numbers = 5 points (55=7)
+            // same numbers = 5 points (11,22,33... but 55=7)
             points += 5;
             // println!("NN add 5, val={}, pt={}", value, points);
         }
 
         if points == 0 {
+            // rest of the cards are 1 point
             points = 1;
         }
 
+        // Return a Card
         Card {
             value,
             points,
@@ -41,20 +50,24 @@
 }
 
 impl fmt::Display for Card {
+    /// Print formatter for a card, so it can be written in `println!()`
     fn fmt( &self, f: &mut fmt::Formatter ) -> fmt::Result {
         write!(f, "(Card {}, points {})", self.value, self.points)
     }
 }
 
 impl PartialEq for Card {
+    /// This is used for sorting cards.
     fn eq(&self, other: &Self) -> bool {
         self.value == other.value
     }
 }
 
+/// This is used for sorting cards. Eq is required some by some strict sorting methods.
 impl Eq for Card {} 
 
 impl PartialOrd for Card {
+    /// This is used for sorting cards.
     fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
         match self.value.partial_cmp(&other.value) {
             Some(core::cmp::Ordering::Equal) => {None}
@@ -63,6 +76,7 @@
     }
 }
 
+/// This is used for sorting cards. Ord (and Eq) is required some by some strict sorting methods.
 impl Ord for Card {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
         self.value.cmp(&other.value)