feat: completed solutions
This commit is contained in:
@@ -41,7 +41,19 @@ enum ParsePersonError {
|
||||
impl FromStr for Person {
|
||||
type Err = ParsePersonError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {}
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.split(",").collect::<Vec<&str>>().as_slice() {
|
||||
[name, age] if (!name.is_empty()) => match age.parse::<u8>() {
|
||||
Ok(age) => Ok(Person {
|
||||
name: name.to_string(),
|
||||
age,
|
||||
}),
|
||||
Err(err) => Err(ParsePersonError::ParseInt(err)),
|
||||
},
|
||||
["", _] => Err(ParsePersonError::NoName),
|
||||
_ => Err(ParsePersonError::BadLen),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user