1
1
//! The `FileType` struct.
2
2
3
- use crate :: fs:: FileTypeExt ;
3
+ use crate :: fs:: ImplFileTypeExt ;
4
4
5
5
/// `FileType`'s inner state.
6
6
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -15,7 +15,7 @@ enum Inner {
15
15
Unknown ,
16
16
17
17
/// A `FileTypeExt` type.
18
- Ext ( FileTypeExt ) ,
18
+ Ext ( ImplFileTypeExt ) ,
19
19
}
20
20
21
21
/// A structure representing a type of file with accessors for each file type.
@@ -51,7 +51,7 @@ impl FileType {
51
51
52
52
/// Creates a `FileType` from extension type.
53
53
#[ inline]
54
- pub ( crate ) const fn ext ( ext : FileTypeExt ) -> Self {
54
+ pub ( crate ) const fn ext ( ext : ImplFileTypeExt ) -> Self {
55
55
Self ( Inner :: Ext ( ext) )
56
56
}
57
57
@@ -84,62 +84,65 @@ impl FileType {
84
84
}
85
85
}
86
86
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 ;
108
100
}
109
101
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 {
112
104
#[ inline]
113
105
fn is_block_device ( & self ) -> bool {
114
- self . 0 == Inner :: Ext ( FileTypeExt :: BlockDevice )
106
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: block_device ( ) )
115
107
}
116
108
117
109
#[ inline]
118
110
fn is_char_device ( & self ) -> bool {
119
- self . 0 == Inner :: Ext ( FileTypeExt :: CharDevice )
111
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: char_device ( ) )
120
112
}
121
113
122
114
#[ inline]
123
115
fn is_fifo ( & self ) -> bool {
124
- self . 0 == Inner :: Ext ( FileTypeExt :: Fifo )
116
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: fifo ( ) )
125
117
}
126
118
127
119
#[ inline]
128
120
fn is_socket ( & self ) -> bool {
129
- self . 0 == Inner :: Ext ( FileTypeExt :: Socket )
121
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: socket ( ) )
130
122
}
131
123
}
132
124
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
+
133
136
#[ cfg( all( windows, windows_file_type_ext) ) ]
134
- impl std :: os :: windows :: fs :: FileTypeExt for FileType {
137
+ impl FileTypeExt for FileType {
135
138
#[ inline]
136
139
fn is_symlink_dir ( & self ) -> bool {
137
- self . 0 == Inner :: Ext ( FileTypeExt :: symlink_dir ( ) )
140
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: symlink_dir ( ) )
138
141
}
139
142
140
143
#[ inline]
141
144
fn is_symlink_file ( & self ) -> bool {
142
- self . 0 == Inner :: Ext ( FileTypeExt :: symlink_file ( ) )
145
+ self . 0 == Inner :: Ext ( ImplFileTypeExt :: symlink_file ( ) )
143
146
}
144
147
}
145
148
0 commit comments