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