1
1
// miri has some special hacks here that make things unused.
2
2
#![ cfg_attr( miri, allow( unused) ) ]
3
3
4
+ #[ cfg( test) ]
5
+ mod tests;
6
+
4
7
use crate :: os:: unix:: prelude:: * ;
5
8
6
9
use crate :: ffi:: { CStr , OsStr , OsString } ;
@@ -354,7 +357,7 @@ pub struct DirEntry {
354
357
entry : dirent64 ,
355
358
}
356
359
357
- #[ derive( Clone , Debug ) ]
360
+ #[ derive( Clone ) ]
358
361
pub struct OpenOptions {
359
362
// generic
360
363
read : bool ,
@@ -368,7 +371,7 @@ pub struct OpenOptions {
368
371
mode : mode_t ,
369
372
}
370
373
371
- #[ derive( Clone , PartialEq , Eq , Debug ) ]
374
+ #[ derive( Clone , PartialEq , Eq ) ]
372
375
pub struct FilePermissions {
373
376
mode : mode_t ,
374
377
}
@@ -381,7 +384,7 @@ pub struct FileTimes {
381
384
created : Option < SystemTime > ,
382
385
}
383
386
384
- #[ derive( Copy , Clone , Eq , Debug ) ]
387
+ #[ derive( Copy , Clone , Eq ) ]
385
388
pub struct FileType {
386
389
mode : mode_t ,
387
390
}
@@ -398,11 +401,12 @@ impl core::hash::Hash for FileType {
398
401
}
399
402
}
400
403
401
- #[ derive( Debug ) ]
402
404
pub struct DirBuilder {
403
405
mode : mode_t ,
404
406
}
405
407
408
+ struct Mode ( mode_t ) ;
409
+
406
410
cfg_has_statx ! { {
407
411
impl FileAttr {
408
412
fn from_stat64( stat: stat64) -> Self {
@@ -673,12 +677,26 @@ impl FileType {
673
677
}
674
678
}
675
679
680
+ impl fmt:: Debug for FileType {
681
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
682
+ let FileType { mode } = self ;
683
+ f. debug_struct ( "FileType" ) . field ( "mode" , & Mode ( * mode) ) . finish ( )
684
+ }
685
+ }
686
+
676
687
impl FromInner < u32 > for FilePermissions {
677
688
fn from_inner ( mode : u32 ) -> FilePermissions {
678
689
FilePermissions { mode : mode as mode_t }
679
690
}
680
691
}
681
692
693
+ impl fmt:: Debug for FilePermissions {
694
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
695
+ let FilePermissions { mode } = self ;
696
+ f. debug_struct ( "FilePermissions" ) . field ( "mode" , & Mode ( * mode) ) . finish ( )
697
+ }
698
+ }
699
+
682
700
impl fmt:: Debug for ReadDir {
683
701
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
684
702
// This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
@@ -1116,6 +1134,23 @@ impl OpenOptions {
1116
1134
}
1117
1135
}
1118
1136
1137
+ impl fmt:: Debug for OpenOptions {
1138
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1139
+ let OpenOptions { read, write, append, truncate, create, create_new, custom_flags, mode } =
1140
+ self ;
1141
+ f. debug_struct ( "OpenOptions" )
1142
+ . field ( "read" , read)
1143
+ . field ( "write" , write)
1144
+ . field ( "append" , append)
1145
+ . field ( "truncate" , truncate)
1146
+ . field ( "create" , create)
1147
+ . field ( "create_new" , create_new)
1148
+ . field ( "custom_flags" , custom_flags)
1149
+ . field ( "mode" , & Mode ( * mode) )
1150
+ . finish ( )
1151
+ }
1152
+ }
1153
+
1119
1154
impl File {
1120
1155
pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
1121
1156
run_path_with_cstr ( path, & |path| File :: open_c ( path, opts) )
@@ -1402,6 +1437,13 @@ impl DirBuilder {
1402
1437
}
1403
1438
}
1404
1439
1440
+ impl fmt:: Debug for DirBuilder {
1441
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1442
+ let DirBuilder { mode } = self ;
1443
+ f. debug_struct ( "DirBuilder" ) . field ( "mode" , & Mode ( * mode) ) . finish ( )
1444
+ }
1445
+ }
1446
+
1405
1447
impl AsInner < FileDesc > for File {
1406
1448
#[ inline]
1407
1449
fn as_inner ( & self ) -> & FileDesc {
@@ -1574,6 +1616,12 @@ impl fmt::Debug for File {
1574
1616
}
1575
1617
}
1576
1618
1619
+ impl fmt:: Debug for Mode {
1620
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1621
+ write ! ( f, "0o{:03o}" , self . 0 )
1622
+ }
1623
+ }
1624
+
1577
1625
pub fn readdir ( path : & Path ) -> io:: Result < ReadDir > {
1578
1626
let ptr = run_path_with_cstr ( path, & |p| unsafe { Ok ( libc:: opendir ( p. as_ptr ( ) ) ) } ) ?;
1579
1627
if ptr. is_null ( ) {
0 commit comments