File tree 1 file changed +12
-6
lines changed
crates/punktf-lib/src/visit/deploy
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -16,23 +16,29 @@ use std::path::Path;
16
16
17
17
use crate :: visit:: { ResolvingVisitor , TemplateVisitor } ;
18
18
19
+ /// Represents the contents of a file as returned by [`safe_read`].
19
20
enum SafeRead {
20
- Binary ( Vec < u8 > ) ,
21
+ /// File was a normal text file.
21
22
String ( String ) ,
23
+
24
+ /// File was unable to be interpreted as a text file.
25
+ Binary ( Vec < u8 > ) ,
22
26
}
23
27
28
+ /// Reads the contents of a file, first trying to interpret them as a string and if that fails
29
+ /// returning the raw bytes.
24
30
fn safe_read < P : AsRef < Path > > ( path : P ) -> io:: Result < SafeRead > {
31
+ /// Inner function to reduce size of monomorphization.
25
32
fn inner ( path : & Path ) -> io:: Result < SafeRead > {
26
33
match std:: fs:: read_to_string ( path) {
27
- Ok ( s) => return Ok ( SafeRead :: String ( s) ) ,
34
+ Ok ( s) => Ok ( SafeRead :: String ( s) ) ,
28
35
Err ( err) if err. kind ( ) == io:: ErrorKind :: InvalidData => {
29
- std:: fs:: read ( path) . map ( |b| SafeRead :: Binary ( b) )
30
- }
31
- Err ( err) => {
32
- return Err ( err) ;
36
+ std:: fs:: read ( path) . map ( SafeRead :: Binary )
33
37
}
38
+ Err ( err) => Err ( err) ,
34
39
}
35
40
}
41
+
36
42
inner ( path. as_ref ( ) )
37
43
}
38
44
You can’t perform that action at this time.
0 commit comments