File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
1
use std:: path:: { Path , Component } ;
2
2
use std:: error:: Error ;
3
- use std:: io;
3
+ use std:: io:: { self , Read } ;
4
4
use std:: fs:: { self , metadata, File } ;
5
5
6
+ /// Takes a path to a file and try to read the file into a String
7
+
8
+ pub fn file_to_string ( path : & Path ) -> Result < String , Box < Error > > {
9
+ let mut file = match File :: open ( path) {
10
+ Ok ( f) => f,
11
+ Err ( e) => {
12
+ debug ! ( "[*]: Failed to open {:?}" , path) ;
13
+ return Err ( Box :: new ( e) ) ;
14
+ } ,
15
+ } ;
16
+
17
+ let mut content = String :: new ( ) ;
18
+
19
+ if let Err ( e) = file. read_to_string ( & mut content) {
20
+ debug ! ( "[*]: Failed to read {:?}" , path) ;
21
+ return Err ( Box :: new ( e) ) ;
22
+ }
23
+
24
+ Ok ( content)
25
+ }
6
26
7
27
/// Takes a path and returns a path containing just enough `../` to point to the root of the given path.
8
28
///
You can’t perform that action at this time.
0 commit comments