From 8bf66050531b0ca8da02c3a296d77b99524715d0 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 12 Nov 2024 21:38:31 +0200 Subject: [PATCH] record progress: from into --- exercises/23_conversions/from_into.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/exercises/23_conversions/from_into.rs b/exercises/23_conversions/from_into.rs index 2a09354..e04c1e4 100644 --- a/exercises/23_conversions/from_into.rs +++ b/exercises/23_conversions/from_into.rs @@ -38,21 +38,19 @@ impl From<&str> for Person { let elements: Vec<&str> = s.split(",").collect(); match elements.as_slice() { - [a, b] => { - if let Ok(age) = b.parse::() { - let name = a.parse().unwrap(); + [nameUnparsed, ageUnparsed] => { + if let Ok(age) = ageUnparsed.parse::() { + 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::default() + Person { + name, + age, + } + } else { + Person::default() + } } &_ => { Person::default()