From b8d6fc45036507ca13d266e70aec3db29194c586 Mon Sep 17 00:00:00 2001
From: Emre AYDIN <aeaydin1@gmail.com>
Date: Wed, 13 Jan 2021 17:58:37 +0300
Subject: [PATCH] Exercises completed this time for sure

---
 exercises/conversions/from_into.rs | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs
index f5a76d0..6df8dd2 100644
--- a/exercises/conversions/from_into.rs
+++ b/exercises/conversions/from_into.rs
@@ -33,21 +33,23 @@ impl Default for Person {
 // If while parsing the age, something goes wrong, then return the default of Person
 // Otherwise, then return an instantiated Person object with the results
 
-// I AM NOT DONE
-
 impl From<&str> for Person {
     fn from(s: &str) -> Person {
         let person: Vec<&str> = s.split(",").collect();
 
-        match person.len() {
-            2 => match person[0].to_owned().len() {
-                0 => Err(String::from("Error")),
-                _ => Ok(Person {
-                    name: person[0].to_owned(),
-                    age: person[1].parse::<usize>().unwrap(),
-                }),
-            },
-            _ => Err(String::from("Error")),
+        if person.len() != 2 {
+            Person::default()
+        } else {
+            let name = person[0].to_owned();
+            if name.len() == 0 {
+                Person::default()
+            } else {
+                let age = person[1].parse::<usize>();
+                match age {
+                    Ok(a) => Person { name, age: a },
+                    _ => Person::default(),
+                }
+            }
         }
     }
 }