11use crate :: file_explorer:: { Entry , Error } ;
2- use std:: io:: ErrorKind ;
32use std:: env:: current_dir;
43use std:: fs:: metadata;
4+ use std:: io:: ErrorKind ;
55use std:: path:: PathBuf ;
66use std:: str:: FromStr ;
77
@@ -36,7 +36,7 @@ impl FileExplorer {
3636
3737 Self {
3838 root_dir : final_path. clone ( ) ,
39- root_dir_string : final_path. to_str ( ) . unwrap ( ) . to_string ( )
39+ root_dir_string : final_path. to_str ( ) . unwrap ( ) . to_string ( ) ,
4040 }
4141 }
4242
@@ -46,12 +46,10 @@ impl FileExplorer {
4646
4747 match metadata ( path. clone ( ) ) {
4848 Ok ( meta) => Ok ( Entry :: new ( path, meta) ) ,
49- Err ( err) => {
50- match err. kind ( ) {
51- ErrorKind :: NotFound => Err ( Error :: NoExists ( path. to_str ( ) . unwrap ( ) . to_string ( ) ) ) ,
52- _ => Err ( Error :: IOError ( err) ) ,
53- }
54- }
49+ Err ( err) => match err. kind ( ) {
50+ ErrorKind :: NotFound => Err ( Error :: NoExists ( path. to_str ( ) . unwrap ( ) . to_string ( ) ) ) ,
51+ _ => Err ( Error :: IOError ( err) ) ,
52+ } ,
5553 }
5654 }
5755
@@ -76,15 +74,16 @@ impl FileExplorer {
7674 }
7775
7876 // retrieve every fragment of the path (directory).
79- let sanitized_path = path. split ( '/' )
77+ let sanitized_path = path
78+ . split ( '/' )
8079 . collect :: < Vec < & str > > ( )
8180 . into_iter ( )
8281 . filter ( |& e| e != "" )
8382 . collect :: < Vec < & str > > ( )
8483 . join ( "/" ) ;
8584
8685 let mut next_path = self . root_dir . clone ( ) ;
87-
86+
8887 next_path. push ( PathBuf :: from_str ( & sanitized_path) . unwrap ( ) ) ;
8988
9089 next_path
@@ -100,7 +99,10 @@ mod tests {
10099 let file_explorer = FileExplorer :: new ( PathBuf :: from_str ( "" ) . unwrap ( ) ) ;
101100 let relative = file_explorer. build_relative_path ( "/" ) ;
102101
103- assert_eq ! ( file_explorer. root_dir. to_str( ) . unwrap( ) , relative. to_str( ) . unwrap( ) ) ;
102+ assert_eq ! (
103+ file_explorer. root_dir. to_str( ) . unwrap( ) ,
104+ relative. to_str( ) . unwrap( )
105+ ) ;
104106 }
105107
106108 #[ test]
@@ -112,7 +114,10 @@ mod tests {
112114
113115 let relative = file_explorer. build_relative_path ( "/music/favorites" ) ;
114116
115- assert_eq ! ( root_dir_on_music. to_str( ) . unwrap( ) , relative. to_str( ) . unwrap( ) ) ;
117+ assert_eq ! (
118+ root_dir_on_music. to_str( ) . unwrap( ) ,
119+ relative. to_str( ) . unwrap( )
120+ ) ;
116121 }
117122
118123 #[ test]
@@ -124,6 +129,9 @@ mod tests {
124129
125130 let relative = file_explorer. build_relative_path ( "//music/favorites" ) ;
126131
127- assert_eq ! ( root_dir_on_music. to_str( ) . unwrap( ) , relative. to_str( ) . unwrap( ) ) ;
132+ assert_eq ! (
133+ root_dir_on_music. to_str( ) . unwrap( ) ,
134+ relative. to_str( ) . unwrap( )
135+ ) ;
128136 }
129137}
0 commit comments