11//! The `FileType` struct.
22
3- use crate :: fs:: FileTypeExt ;
3+ use crate :: fs:: ImplFileTypeExt ;
44
55/// `FileType`'s inner state.
66#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -15,7 +15,7 @@ enum Inner {
1515 Unknown ,
1616
1717 /// A `FileTypeExt` type.
18- Ext ( FileTypeExt ) ,
18+ Ext ( ImplFileTypeExt ) ,
1919}
2020
2121/// A structure representing a type of file with accessors for each file type.
@@ -51,7 +51,7 @@ impl FileType {
5151
5252 /// Creates a `FileType` from extension type.
5353 #[ inline]
54- pub ( crate ) const fn ext ( ext : FileTypeExt ) -> Self {
54+ pub ( crate ) const fn ext ( ext : ImplFileTypeExt ) -> Self {
5555 Self ( Inner :: Ext ( ext) )
5656 }
5757
@@ -84,62 +84,65 @@ impl FileType {
8484 }
8585}
8686
87- #[ cfg( unix) ]
88- impl std:: os:: unix:: fs:: FileTypeExt for FileType {
89- #[ inline]
90- fn is_block_device ( & self ) -> bool {
91- self . 0 == Inner :: Ext ( crate :: fs:: FileTypeExt :: block_device ( ) )
92- }
93-
94- #[ inline]
95- fn is_char_device ( & self ) -> bool {
96- self . 0 == Inner :: Ext ( FileTypeExt :: char_device ( ) )
97- }
98-
99- #[ inline]
100- fn is_fifo ( & self ) -> bool {
101- self . 0 == Inner :: Ext ( FileTypeExt :: fifo ( ) )
102- }
103-
104- #[ inline]
105- fn is_socket ( & self ) -> bool {
106- self . 0 == Inner :: Ext ( FileTypeExt :: socket ( ) )
107- }
87+ /// Unix-specific extensions for [`FileType`].
88+ ///
89+ /// This corresponds to [`std::os::unix::fs::FileTypeExt`].
90+ #[ cfg( any( unix, target_os = "vxworks" ) ) ]
91+ pub trait FileTypeExt {
92+ /// Returns `true` if this file type is a block device.
93+ fn is_block_device ( & self ) -> bool ;
94+ /// Returns `true` if this file type is a character device.
95+ fn is_char_device ( & self ) -> bool ;
96+ /// Returns `true` if this file type is a fifo.
97+ fn is_fifo ( & self ) -> bool ;
98+ /// Returns `true` if this file type is a socket.
99+ fn is_socket ( & self ) -> bool ;
108100}
109101
110- #[ cfg( target_os = "vxworks" ) ]
111- impl std :: os :: vxworks :: fs :: FileTypeExt for FileType {
102+ #[ cfg( any ( unix , target_os = "vxworks" ) ) ]
103+ impl FileTypeExt for FileType {
112104 #[ inline]
113105 fn is_block_device ( & self ) -> bool {
114- self . 0 == Inner :: Ext ( FileTypeExt :: BlockDevice )
106+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: block_device ( ) )
115107 }
116108
117109 #[ inline]
118110 fn is_char_device ( & self ) -> bool {
119- self . 0 == Inner :: Ext ( FileTypeExt :: CharDevice )
111+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: char_device ( ) )
120112 }
121113
122114 #[ inline]
123115 fn is_fifo ( & self ) -> bool {
124- self . 0 == Inner :: Ext ( FileTypeExt :: Fifo )
116+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: fifo ( ) )
125117 }
126118
127119 #[ inline]
128120 fn is_socket ( & self ) -> bool {
129- self . 0 == Inner :: Ext ( FileTypeExt :: Socket )
121+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: socket ( ) )
130122 }
131123}
132124
125+ /// Windows-specific extensions for [`FileType`].
126+ ///
127+ /// This corresponds to [`std::os::windows::fs::FileTypeExt`].
128+ #[ cfg( all( windows, windows_file_type_ext) ) ]
129+ pub trait FileTypeExt {
130+ /// Returns `true` if this file type is a symbolic link that is also a directory.
131+ fn is_symlink_dir ( & self ) -> bool ;
132+ /// Returns `true` if this file type is a symbolic link that is also a file.
133+ fn is_symlink_file ( & self ) -> bool ;
134+ }
135+
133136#[ cfg( all( windows, windows_file_type_ext) ) ]
134- impl std :: os :: windows :: fs :: FileTypeExt for FileType {
137+ impl FileTypeExt for FileType {
135138 #[ inline]
136139 fn is_symlink_dir ( & self ) -> bool {
137- self . 0 == Inner :: Ext ( FileTypeExt :: symlink_dir ( ) )
140+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: symlink_dir ( ) )
138141 }
139142
140143 #[ inline]
141144 fn is_symlink_file ( & self ) -> bool {
142- self . 0 == Inner :: Ext ( FileTypeExt :: symlink_file ( ) )
145+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: symlink_file ( ) )
143146 }
144147}
145148
0 commit comments