Exercises completed this time for sure

This commit is contained in:
Emre AYDIN 2021-01-13 17:58:37 +03:00
parent 9d5237824b
commit b8d6fc4503

View file

@ -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(),
}
}
}
}
}