File tree 6 files changed +26
-31
lines changed
6 files changed +26
-31
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ edition = "2021"
6
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
8
8
[dependencies ]
9
+ misc = { path = " ../misc" }
Original file line number Diff line number Diff line change 1
- use std:: fs;
2
-
1
+ use misc:: load_text;
3
2
4
3
fn scratchcards ( text : String ) -> u32 {
5
4
let mut res = 0 ;
@@ -26,20 +25,6 @@ fn scratchcards(text: String) -> u32{
26
25
return res;
27
26
}
28
27
29
-
30
- fn load_text ( path_file : String ) -> String {
31
- let file_path: String = String :: from ( path_file) ;
32
- let contents = fs:: read_to_string ( file_path) ;
33
-
34
- let mut text: String = String :: from ( "" ) ;
35
- match contents {
36
- Ok ( v) => text = v,
37
- Err ( e) => println ! ( "error parsing header: {e:?}" ) ,
38
- }
39
-
40
- return text;
41
- }
42
-
43
28
fn main ( ) {
44
29
let test_text: String = load_text ( String :: from ( "test.txt" ) ) ;
45
30
let test_value = scratchcards ( test_text) ;
Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ edition = "2021"
6
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
8
8
[dependencies ]
9
+ misc = { path = " ../misc" }
Original file line number Diff line number Diff line change 1
- use std :: fs ;
1
+ use misc :: load_text ;
2
2
use std:: collections:: HashMap ;
3
3
4
4
fn _scratchcards ( text : & str , card_number : u32 ) -> u32 {
@@ -51,20 +51,6 @@ fn scratchcards(text: &str) -> u32{
51
51
return res;
52
52
}
53
53
54
-
55
- fn load_text ( path_file : String ) -> String {
56
- let file_path: String = String :: from ( path_file) ;
57
- let contents = fs:: read_to_string ( file_path) ;
58
-
59
- let mut text: String = String :: from ( "" ) ;
60
- match contents {
61
- Ok ( v) => text = v,
62
- Err ( e) => println ! ( "error parsing header: {e:?}" ) ,
63
- }
64
-
65
- return text;
66
- }
67
-
68
54
fn main ( ) {
69
55
let test_text: String = load_text ( String :: from ( "test.txt" ) ) ;
70
56
let test_value = scratchcards ( test_text. as_str ( ) ) ;
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " misc"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ use std:: fs;
2
+
3
+ pub fn load_text ( path_file : String ) -> String {
4
+ let file_path: String = String :: from ( path_file) ;
5
+ let contents = fs:: read_to_string ( file_path) ;
6
+
7
+ let mut text: String = String :: from ( "" ) ;
8
+ match contents {
9
+ Ok ( v) => text = v,
10
+ Err ( e) => println ! ( "error parsing header: {e:?}" ) ,
11
+ }
12
+
13
+ return text;
14
+ }
You can’t perform that action at this time.
0 commit comments