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(); let elements: Vec<&str> = s.split(",").collect();
match elements.as_slice() { match elements.as_slice() {
[a, b] => { [nameUnparsed, ageUnparsed] => {
if let Ok(age) = b.parse::<u8>() { if let Ok(age) = ageUnparsed.parse::<u8>() {
let name = a.parse().unwrap(); let name = nameUnparsed.parse().unwrap();
if name == "" { if name == "" {
return Person { return Person::default();
name: String::from("John"),
age: age,
};
} }
return Person { Person {
name: name, name,
age: age, age,
}; }
}; } else {
Person::default() Person::default()
}
} }
&_ => { &_ => {
Person::default() Person::default()