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();
|
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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue