@@ -9,10 +9,8 @@ use std::path::{Path, PathBuf};
99use std:: sync:: LazyLock ;
1010use unindent:: unindent;
1111
12-
13- static ENCODING_RE : LazyLock < Regex > = LazyLock :: new ( || {
14- Regex :: new ( r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)" ) . unwrap ( )
15- } ) ;
12+ static ENCODING_RE : LazyLock < Regex > =
13+ LazyLock :: new ( || Regex :: new ( r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)" ) . unwrap ( ) ) ;
1614
1715pub trait FileSystem : Send + Sync {
1816 fn sep ( & self ) -> & str ;
@@ -47,7 +45,9 @@ impl FileSystem for RealBasicFileSystem {
4745 for component in components {
4846 path. push ( component) ;
4947 }
50- path. to_str ( ) . expect ( "Path components should be valid unicode" ) . to_string ( )
48+ path. to_str ( )
49+ . expect ( "Path components should be valid unicode" )
50+ . to_string ( )
5151 }
5252
5353 fn split ( & self , file_name : & str ) -> ( String , String ) {
@@ -66,8 +66,12 @@ impl FileSystem for RealBasicFileSystem {
6666 } ;
6767
6868 (
69- head. to_str ( ) . expect ( "Path components should be valid unicode" ) . to_string ( ) ,
70- tail. to_str ( ) . expect ( "Path components should be valid unicode" ) . to_string ( ) ,
69+ head. to_str ( )
70+ . expect ( "Path components should be valid unicode" )
71+ . to_string ( ) ,
72+ tail. to_str ( )
73+ . expect ( "Path components should be valid unicode" )
74+ . to_string ( ) ,
7175 )
7276 }
7377
@@ -88,17 +92,17 @@ impl FileSystem for RealBasicFileSystem {
8892 } ) ?;
8993
9094 let s = String :: from_utf8_lossy ( & bytes) ;
91-
9295
9396 let mut detected_encoding: Option < String > = None ;
9497
9598 // Coding specification needs to be in the first two lines, or it's ignored.
9699 for line in s. lines ( ) . take ( 2 ) {
97100 if let Some ( captures) = ENCODING_RE . captures ( line)
98- && let Some ( encoding_name) = captures. get ( 1 ) {
99- detected_encoding = Some ( encoding_name. as_str ( ) . to_string ( ) ) ;
100- break ;
101- }
101+ && let Some ( encoding_name) = captures. get ( 1 )
102+ {
103+ detected_encoding = Some ( encoding_name. as_str ( ) . to_string ( ) ) ;
104+ break ;
105+ }
102106 }
103107
104108 if let Some ( enc_name) = detected_encoding {
@@ -217,8 +221,12 @@ impl FileSystem for FakeBasicFileSystem {
217221 tail = path. file_name ( ) . unwrap_or ( OsStr :: new ( "" ) ) ;
218222 }
219223 (
220- head. to_str ( ) . expect ( "Path components should be valid unicode" ) . to_string ( ) ,
221- tail. to_str ( ) . expect ( "Path components should be valid unicode" ) . to_string ( ) ,
224+ head. to_str ( )
225+ . expect ( "Path components should be valid unicode" )
226+ . to_string ( ) ,
227+ tail. to_str ( )
228+ . expect ( "Path components should be valid unicode" )
229+ . to_string ( ) ,
222230 )
223231 }
224232
@@ -230,7 +238,9 @@ impl FileSystem for FakeBasicFileSystem {
230238 fn read ( & self , file_name : & str ) -> PyResult < String > {
231239 match self . contents . get ( file_name) {
232240 Some ( file_name) => Ok ( file_name. clone ( ) ) ,
233- None => Err ( PyFileNotFoundError :: new_err ( format ! ( "No such file: {file_name}" ) ) ) ,
241+ None => Err ( PyFileNotFoundError :: new_err ( format ! (
242+ "No such file: {file_name}"
243+ ) ) ) ,
234244 }
235245 }
236246}
@@ -267,11 +277,11 @@ impl PyFakeBasicFileSystem {
267277 fn read ( & self , file_name : & str ) -> PyResult < String > {
268278 self . inner . read ( file_name)
269279 }
270-
280+
271281 // Temporary workaround method for Python tests.
272282 fn convert_to_basic ( & self ) -> PyResult < Self > {
273283 Ok ( PyFakeBasicFileSystem {
274- inner : self . inner . clone ( )
284+ inner : self . inner . clone ( ) ,
275285 } )
276286 }
277287}
@@ -354,7 +364,10 @@ pub fn parse_indented_file_system_string(file_system_string: &str) -> HashMap<St
354364 // Edge case: If the very first line was a file and it ended up on the stack, it needs to be processed.
355365 // This handles single-file inputs like "myfile.txt"
356366 if !path_stack. is_empty ( )
357- && !path_stack. last ( ) . expect ( "path_stack should be non-empty" ) . ends_with ( '/' )
367+ && !path_stack
368+ . last ( )
369+ . expect ( "path_stack should be non-empty" )
370+ . ends_with ( '/' )
358371 && !file_paths_map. contains_key ( & path_stack. join ( "/" ) )
359372 {
360373 file_paths_map. insert ( path_stack. join ( "/" ) , String :: new ( ) ) ;
0 commit comments