|
| 1 | +use cap_primitives::fs::is_file_read_write; |
| 2 | +use std::io; |
| 3 | +use unsafe_io::AsUnsafeFile; |
| 4 | + |
| 5 | +/// A trait for the `is_file_read_write` function for `File` types. |
| 6 | +/// |
| 7 | +/// This is only implemented for `File` types; for arbitrary I/O handles, use |
| 8 | +/// [`system_interface::io::IsReadWrite`] instead. |
| 9 | +/// |
| 10 | +/// [`system_interface::io::IsReadWrite`]: https://docs.rs/system-interface/latest/system_interface/io/trait.ReadReady.html |
| 11 | +pub trait IsFileReadWrite { |
| 12 | + /// Test whether the given file is readable and/or writable. |
| 13 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)>; |
| 14 | +} |
| 15 | + |
| 16 | +impl IsFileReadWrite for std::fs::File { |
| 17 | + #[inline] |
| 18 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 19 | + is_file_read_write(self) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +#[cfg(all(feature = "std"))] |
| 24 | +impl IsFileReadWrite for cap_std::fs::File { |
| 25 | + #[inline] |
| 26 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 27 | + is_file_read_write(&self.as_file_view()) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +#[cfg(all(feature = "std", feature = "fs_utf8"))] |
| 32 | +impl IsFileReadWrite for cap_std::fs_utf8::File { |
| 33 | + #[inline] |
| 34 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 35 | + is_file_read_write(&self.as_file_view()) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +#[cfg(all(feature = "async_std"))] |
| 40 | +impl IsFileReadWrite for async_std::fs::File { |
| 41 | + #[inline] |
| 42 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 43 | + is_file_read_write(&self.as_file_view()) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +#[cfg(all(feature = "async_std"))] |
| 48 | +impl IsFileReadWrite for cap_async_std::fs::File { |
| 49 | + #[inline] |
| 50 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 51 | + is_file_read_write(&self.as_file_view()) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +#[cfg(all(feature = "async_std", feature = "fs_utf8"))] |
| 56 | +impl IsFileReadWrite for cap_async_std::fs_utf8::File { |
| 57 | + #[inline] |
| 58 | + fn is_file_read_write(&self) -> io::Result<(bool, bool)> { |
| 59 | + is_file_read_write(&self.as_file_view()) |
| 60 | + } |
| 61 | +} |
0 commit comments