feat: completed solutions
This commit is contained in:
@@ -34,7 +34,18 @@ impl Default for Person {
|
||||
// 5. Parse the second element from the split operation into a `u8` as the age.
|
||||
// 6. If parsing the age fails, return the default of `Person`.
|
||||
impl From<&str> for Person {
|
||||
fn from(s: &str) -> Self {}
|
||||
fn from(s: &str) -> Self {
|
||||
match s.split(",").collect::<Vec<&str>>().as_slice() {
|
||||
[name, age] if (!name.is_empty() && !age.is_empty()) => match age.parse::<u8>() {
|
||||
Ok(age) => Person {
|
||||
name: name.to_string(),
|
||||
age,
|
||||
},
|
||||
Err(_) => Person::default(),
|
||||
},
|
||||
_ => Person::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user