Repository: cholcombe973/block-utils (language: rust)

Issue:
fmt::Display impl of BlockUtilsError have a infinite recursive loop
First of all, thanks for this lib, has been very useful.

The problem is that `fmt::Display` impl of BlockUtilsError calls `self.to_string()` whom implementation is in `ToString` trait, who depend on `Display`. So what happens, Display::fmt()  calls ToString::to_string() who calls Display::fmt() and so on. This is only triggered if you try to format the error.


Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index 20196ac..8369a9d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -84,7 +84,14 @@ pub enum BlockUtilsError {
 
 impl fmt::Display for BlockUtilsError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.write_str(&self.to_string())
+        f.write_str("BlockUtilsError : ")?;
+        match *self {
+            BlockUtilsError::Error(ref e) => f.write_str(e),
+            BlockUtilsError::IoError(ref e) => f.write_str(&e.to_string()),
+            BlockUtilsError::ParseBoolError(ref e) => f.write_str(&e.to_string()),
+            BlockUtilsError::ParseIntError(ref e) => f.write_str(&e.to_string()),
+            BlockUtilsError::SerdeError(ref e) => f.write_str(&e.to_string()),
+        }
     }
 }
 


Test patch: