record progress: from into

This commit is contained in:
Denis-Cosmin Nutiu 2024-11-12 21:38:31 +02:00
parent 7cd24e4973
commit 8bf6605053

View file

@ -38,21 +38,19 @@ impl From<&str> for Person {
let elements: Vec<&str> = s.split(",").collect();
match elements.as_slice() {
[a, b] => {
if let Ok(age) = b.parse::<u8>() {
let name = a.parse().unwrap();
[nameUnparsed, ageUnparsed] => {
if let Ok(age) = ageUnparsed.parse::<u8>() {
let name = nameUnparsed.parse().unwrap();
if name == "" {
return Person {
name: String::from("John"),
age: age,
};
return Person::default();
}
return Person {
name: name,
age: age,
};
};
Person::default()
Person {
name,
age,
}
} else {
Person::default()
}
}
&_ => {
Person::default()