|
|
@@ -56,9 +56,13 @@ fn concatenate_strings<'a>(s1: &'a str, s2: &'a str) -> String {
|
|
56
|
56
|
}
|
|
57
|
57
|
|
|
58
|
58
|
/// Splits the given String reference and returns it as Vector.
|
|
59
|
|
-/*fn split_into_strings<'2>(s1:&'a str) -> Vec<&'a str> {
|
|
60
|
|
- s1.to_string().split_whitespace().collect()
|
|
61
|
|
-}*/
|
|
|
59
|
+fn split_into_strings<'a>(s1: &'a str) -> Vec<String> {
|
|
|
60
|
+ s1.to_string()
|
|
|
61
|
+ .split_whitespace()
|
|
|
62
|
+ .map(|s| s.to_string())
|
|
|
63
|
+ .collect()
|
|
|
64
|
+}
|
|
|
65
|
+
|
|
62
|
66
|
/// Calculates the sum of the given Strings and returns them as a Result.
|
|
63
|
67
|
fn sum_strings(v: Vec<&str>) -> Result<i32, &str> {
|
|
64
|
68
|
let mut sum = 0;
|
|
|
@@ -66,7 +70,9 @@ fn sum_strings(v: Vec<&str>) -> Result<i32, &str> {
|
|
66
|
70
|
match x.parse::<i32>() {
|
|
67
|
71
|
Ok(val) => {
|
|
68
|
72
|
match i32::checked_add(sum, val) {
|
|
69
|
|
- Some(y) => {sum = y;}
|
|
|
73
|
+ Some(y) => {
|
|
|
74
|
+ sum = y;
|
|
|
75
|
+ }
|
|
70
|
76
|
None => return Err("Overflow"),
|
|
71
|
77
|
}
|
|
72
|
78
|
}
|
|
|
@@ -83,7 +89,9 @@ fn mul_strings(v: Vec<&str>) -> Result<i32, &str> {
|
|
83
|
89
|
match x.parse::<i32>() {
|
|
84
|
90
|
Ok(val) => {
|
|
85
|
91
|
match i32::checked_mul(prod, val) {
|
|
86
|
|
- Some(y) => {prod = y;}
|
|
|
92
|
+ Some(y) => {
|
|
|
93
|
+ prod = y;
|
|
|
94
|
+ }
|
|
87
|
95
|
None => return Err("Overflow"),
|
|
88
|
96
|
}
|
|
89
|
97
|
}
|