Jelajahi Sumber

rustfmt flags.rs.

Steve Thielemann 1 Minggu lalu
induk
melakukan
fba9c1531b
1 mengubah file dengan 31 tambahan dan 11 penghapusan
  1. 31 11
      sudoku/src/flags.rs

+ 31 - 11
sudoku/src/flags.rs

@@ -1,13 +1,13 @@
 //! Bits
-//! 
+//!
 //! Handles if a certain bit is set. Vec<bool>
 
-use std::ops::RangeBounds;
 use std::fmt;
+use std::ops::RangeBounds;
 // use std::iter::{Map, Filter, Enumerate};
 
 /// Flags - track what is set
-/// 
+///
 /// A vector of bool with helper functions to track what is set (true) and not (false).
 #[derive(Clone)]
 pub struct Flags(pub Vec<bool>);
@@ -22,7 +22,7 @@ impl Flags {
     #[inline]
     pub fn clear(&mut self) {
         self.0.fill(false);
-        /* 
+        /*
         for i in 0..self.0.len() {
             self.0[i] = false;
         }
@@ -101,14 +101,34 @@ impl Flags {
 }
 
 impl fmt::Debug for Flags {
-        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-            write!(f, "({})", self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0.to_string()).collect::<Vec<_>>().join(","))
-        }
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(
+            f,
+            "({})",
+            self.0
+                .iter()
+                .enumerate()
+                .filter(|x| *x.1)
+                .map(|x| x.0.to_string())
+                .collect::<Vec<_>>()
+                .join(",")
+        )
+    }
 }
 
 impl fmt::Display for Flags {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "({})", self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0.to_string()).collect::<Vec<_>>().join(","))
+        write!(
+            f,
+            "({})",
+            self.0
+                .iter()
+                .enumerate()
+                .filter(|x| *x.1)
+                .map(|x| x.0.to_string())
+                .collect::<Vec<_>>()
+                .join(",")
+        )
     }
 }
 
@@ -133,13 +153,13 @@ use std::ops::{Index, IndexMut};
 impl Index<usize> for Flags {
     type Output = bool;
 
-    fn index<'a>(&'a self, i:usize) -> &'a bool {
+    fn index<'a>(&'a self, i: usize) -> &'a bool {
         &self.0[i]
     }
 }
 
 impl IndexMut<usize> for Flags {
-    fn index_mut<'a>(&'a mut self, i:usize) -> &'a mut bool {
+    fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut bool {
         &mut self.0[i]
     }
 }
@@ -169,7 +189,7 @@ mod tests {
         for i in 0..9 {
             let mut result = p[i];
             assert_eq!(result, false);
-            p[i] =true;
+            p[i] = true;
             result = p[i];
             assert_eq!(result, true);
         }