From 1336838264d7776d8dd7890e971ac83e7c7db9fa Mon Sep 17 00:00:00 2001
From: lukaszKielar <kielar.lukasz@hotmail.com>
Date: Tue, 30 Jun 2020 21:54:08 +0200
Subject: [PATCH] finish from_into exercise

---
 exercises/conversions/from_into.rs | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs
index 8fb9eb0..428a0a6 100644
--- a/exercises/conversions/from_into.rs
+++ b/exercises/conversions/from_into.rs
@@ -18,7 +18,6 @@ impl Default for Person {
     }
 }
 
-// I AM NOT DONE
 // Your task is to complete this implementation
 // in order for the line `let p = Person::from("Mark,20")` to compile
 // Please note that you'll need to parse the age component into a `usize`
@@ -35,6 +34,34 @@ impl Default for Person {
 // Otherwise, then return an instantiated Person object with the results
 impl From<&str> for Person {
     fn from(s: &str) -> Person {
+        if s.len() == 0 {
+            Person::default()
+        } else {
+            let elems: Vec<&str> = s.split(",").collect();
+            
+            // missing comma
+            if elems.len() != 2 {
+                return Person::default();
+            }
+
+            let name = elems[0].to_string();
+            let age = elems[1];
+
+            if name.len() == 0 {
+                return Person::default();
+            }
+
+            if age.len() == 0 {
+                return Person::default();
+            }
+
+            let age = match age.parse::<usize>() {
+                Ok(age) => age,
+                Err(_) => return Person::default(),
+            };
+
+            Person { name, age }
+        }
     }
 }