record progress: from into
This commit is contained in:
parent
7cd24e4973
commit
8bf6605053
1 changed files with 11 additions and 13 deletions
|
@ -38,22 +38,20 @@ 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 {
|
||||
name,
|
||||
age,
|
||||
}
|
||||
} else {
|
||||
Person::default()
|
||||
}
|
||||
}
|
||||
&_ => {
|
||||
Person::default()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue