Browse Source

Made one fuction working, rustfmt

Lorenz Bung 8 years ago
parent
commit
cd4c7346a5
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      hw6/task1/src/main.rs

+ 13
- 5
hw6/task1/src/main.rs View File

56
 }
56
 }
57
 
57
 
58
 /// Splits the given String reference and returns it as Vector.
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
 /// Calculates the sum of the given Strings and returns them as a Result.
66
 /// Calculates the sum of the given Strings and returns them as a Result.
63
 fn sum_strings(v: Vec<&str>) -> Result<i32, &str> {
67
 fn sum_strings(v: Vec<&str>) -> Result<i32, &str> {
64
     let mut sum = 0;
68
     let mut sum = 0;
66
         match x.parse::<i32>() {
70
         match x.parse::<i32>() {
67
             Ok(val) => {
71
             Ok(val) => {
68
                 match i32::checked_add(sum, val) {
72
                 match i32::checked_add(sum, val) {
69
-                    Some(y) => {sum = y;}
73
+                    Some(y) => {
74
+                        sum = y;
75
+                    }
70
                     None => return Err("Overflow"),
76
                     None => return Err("Overflow"),
71
                 }
77
                 }
72
             }
78
             }
83
         match x.parse::<i32>() {
89
         match x.parse::<i32>() {
84
             Ok(val) => {
90
             Ok(val) => {
85
                 match i32::checked_mul(prod, val) {
91
                 match i32::checked_mul(prod, val) {
86
-                    Some(y) => {prod = y;}
92
+                    Some(y) => {
93
+                        prod = y;
94
+                    }
87
                     None => return Err("Overflow"),
95
                     None => return Err("Overflow"),
88
                 }
96
                 }
89
             }
97
             }

Loading…
Cancel
Save