cap_fs_ext/
file_type_ext.rs

1#[cfg(windows)]
2use cap_primitives::fs::_WindowsFileTypeExt;
3
4/// Extension trait for `FileType`.
5pub trait FileTypeExt {
6    /// Returns `true` if this file type is a block device.
7    ///
8    /// This corresponds to
9    /// [`std::os::unix::fs::FileTypeExt::is_block_device`], except that it's
10    /// supported on Windows platforms as well.
11    ///
12    /// [`std::os::unix::fs::FileTypeExt::is_block_device`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_block_device
13    fn is_block_device(&self) -> bool;
14
15    /// Returns `true` if this file type is a char device.
16    ///
17    /// This corresponds to
18    /// [`std::os::unix::fs::FileTypeExt::is_char_device`], except that it's
19    /// supported on Windows platforms as well.
20    ///
21    /// [`std::os::unix::fs::FileTypeExt::is_char_device`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_char_device
22    fn is_char_device(&self) -> bool;
23
24    /// Returns `true` if this file type is a fifo.
25    ///
26    /// This corresponds to
27    /// [`std::os::unix::fs::FileTypeExt::is_fifo`], except that it's supported
28    /// on Windows platforms as well.
29    ///
30    /// [`std::os::unix::fs::FileTypeExt::is_fifo`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_fifo
31    fn is_fifo(&self) -> bool;
32
33    /// Returns `true` if this file type is a socket.
34    ///
35    /// This corresponds to
36    /// [`std::os::unix::fs::FileTypeExt::is_socket`], except that it's
37    /// supported on Windows platforms as well.
38    ///
39    /// [`std::os::unix::fs::FileTypeExt::is_socket`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_socket
40    fn is_socket(&self) -> bool;
41}
42
43#[cfg(not(windows))]
44impl FileTypeExt for std::fs::FileType {
45    #[inline]
46    fn is_block_device(&self) -> bool {
47        std::os::unix::fs::FileTypeExt::is_block_device(self)
48    }
49
50    #[inline]
51    fn is_char_device(&self) -> bool {
52        std::os::unix::fs::FileTypeExt::is_char_device(self)
53    }
54
55    #[inline]
56    fn is_fifo(&self) -> bool {
57        std::os::unix::fs::FileTypeExt::is_fifo(self)
58    }
59
60    #[inline]
61    fn is_socket(&self) -> bool {
62        std::os::unix::fs::FileTypeExt::is_socket(self)
63    }
64}
65
66#[cfg(all(not(windows), any(feature = "std", feature = "async_std")))]
67impl FileTypeExt for cap_primitives::fs::FileType {
68    #[inline]
69    fn is_block_device(&self) -> bool {
70        cap_primitives::fs::FileTypeExt::is_block_device(self)
71    }
72
73    #[inline]
74    fn is_char_device(&self) -> bool {
75        cap_primitives::fs::FileTypeExt::is_char_device(self)
76    }
77
78    #[inline]
79    fn is_fifo(&self) -> bool {
80        cap_primitives::fs::FileTypeExt::is_fifo(self)
81    }
82
83    #[inline]
84    fn is_socket(&self) -> bool {
85        cap_primitives::fs::FileTypeExt::is_socket(self)
86    }
87}
88
89#[cfg(all(windows, any(feature = "std", feature = "async_std")))]
90impl FileTypeExt for cap_primitives::fs::FileType {
91    #[inline]
92    fn is_block_device(&self) -> bool {
93        _WindowsFileTypeExt::is_block_device(self)
94    }
95
96    #[inline]
97    fn is_char_device(&self) -> bool {
98        _WindowsFileTypeExt::is_char_device(self)
99    }
100
101    #[inline]
102    fn is_fifo(&self) -> bool {
103        _WindowsFileTypeExt::is_fifo(self)
104    }
105
106    #[inline]
107    fn is_socket(&self) -> bool {
108        _WindowsFileTypeExt::is_socket(self)
109    }
110}