@@ -1797,7 +1797,6 @@ pub struct UnstableFileStat {
1797
1797
bitflags ! (
1798
1798
#[ doc="A set of permissions for a file or directory is represented
1799
1799
by a set of flags which are or'd together." ]
1800
- #[ deriving( Show ) ]
1801
1800
flags FilePermission : u32 {
1802
1801
static UserRead = 0o400 ,
1803
1802
static UserWrite = 0o200 ,
@@ -1836,6 +1835,14 @@ impl Default for FilePermission {
1836
1835
fn default ( ) -> FilePermission { FilePermission :: empty ( ) }
1837
1836
}
1838
1837
1838
+ impl fmt:: Show for FilePermission {
1839
+ fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
1840
+ formatter. fill = '0' ;
1841
+ formatter. width = Some ( 4 ) ;
1842
+ ( & self . bits as & fmt:: Octal ) . fmt ( formatter)
1843
+ }
1844
+ }
1845
+
1839
1846
#[ cfg( test) ]
1840
1847
mod tests {
1841
1848
use super :: { IoResult , Reader , MemReader , NoProgress , InvalidInput } ;
@@ -1937,4 +1944,18 @@ mod tests {
1937
1944
let mut r = MemReader :: new ( Vec :: from_slice ( b"hello, world!" ) ) ;
1938
1945
assert_eq ! ( r. push_at_least( 5 , 1 , & mut buf) . unwrap_err( ) . kind, InvalidInput ) ;
1939
1946
}
1947
+
1948
+ #[ test]
1949
+ fn test_show ( ) {
1950
+ use super :: * ;
1951
+
1952
+ assert_eq ! ( format!( "{}" , UserRead ) , "0400" . to_string( ) ) ;
1953
+ assert_eq ! ( format!( "{}" , UserFile ) , "0644" . to_string( ) ) ;
1954
+ assert_eq ! ( format!( "{}" , UserExec ) , "0755" . to_string( ) ) ;
1955
+ assert_eq ! ( format!( "{}" , UserRWX ) , "0700" . to_string( ) ) ;
1956
+ assert_eq ! ( format!( "{}" , GroupRWX ) , "0070" . to_string( ) ) ;
1957
+ assert_eq ! ( format!( "{}" , OtherRWX ) , "0007" . to_string( ) ) ;
1958
+ assert_eq ! ( format!( "{}" , AllPermissions ) , "0777" . to_string( ) ) ;
1959
+ assert_eq ! ( format!( "{}" , UserRead | UserWrite | OtherWrite ) , "0602" . to_string( ) ) ;
1960
+ }
1940
1961
}
0 commit comments