Skip to content

Commit 2283f73

Browse files
committed
Rename IsReadWrite to IsFileReadWrite.
This helps avoid confusion with system-interface's `IsReadWrite`.
1 parent ac4ee44 commit 2283f73

File tree

14 files changed

+87
-87
lines changed

14 files changed

+87
-87
lines changed

cap-async-std/src/fs/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use async_std::{
1010
io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write},
1111
task::{Context, Poll},
1212
};
13-
use cap_primitives::fs::is_read_write;
13+
use cap_primitives::fs::is_file_read_write;
1414
use std::{fmt, pin::Pin};
1515
use unsafe_io::AsUnsafeFile;
1616

@@ -337,7 +337,7 @@ impl fmt::Debug for File {
337337
b.field("fd", &file.as_raw_fd());
338338
#[cfg(windows)]
339339
b.field("handle", &file.as_raw_handle());
340-
if let Ok((read, write)) = is_read_write(&file) {
340+
if let Ok((read, write)) = is_file_read_write(&file) {
341341
b.field("read", &read).field("write", &write);
342342
}
343343
b.finish()

cap-fs-ext/src/is_file_read_write.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

cap-fs-ext/src/is_read_write.rs

Lines changed: 0 additions & 61 deletions
This file was deleted.

cap-fs-ext/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
mod dir_ext;
1313
mod file_type_ext;
14-
mod is_read_write;
14+
mod is_file_read_write;
1515
mod metadata_ext;
1616
mod open_options_follow_ext;
1717
mod reopen;
@@ -20,7 +20,7 @@ mod reopen;
2020
pub use dir_ext::DirExtUtf8;
2121
pub use dir_ext::{DirExt, SystemTimeSpec};
2222
pub use file_type_ext::FileTypeExt;
23-
pub use is_read_write::IsReadWrite;
23+
pub use is_file_read_write::IsFileReadWrite;
2424
pub use metadata_ext::MetadataExt;
2525
pub use open_options_follow_ext::{FollowSymlinks, OpenOptionsFollowExt};
2626
pub use reopen::Reopen;

cap-primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fs-set-times = "0.2.3"
2121
unsafe-io = "0.2.0"
2222

2323
[target.'cfg(not(windows))'.dependencies]
24-
posish = "0.5.4"
24+
posish = "0.5.9"
2525
libc = "0.2.81"
2626

2727
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::fs::is_read_write_impl;
1+
use crate::fs::is_file_read_write_impl;
22
use std::{fs, io};
33

44
/// Return a pair of booleans indicating whether the given file is opened
55
/// for reading and writing, respectively.
66
#[inline]
7-
pub fn is_read_write(file: &fs::File) -> io::Result<(bool, bool)> {
8-
is_read_write_impl(file)
7+
pub fn is_file_read_write(file: &fs::File) -> io::Result<(bool, bool)> {
8+
is_file_read_write_impl(file)
99
}

cap-primitives/src/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod file_path_by_searching;
1515
mod file_type;
1616
mod follow_symlinks;
1717
mod hard_link;
18-
mod is_read_write;
18+
mod is_file_read_write;
1919
mod maybe_owned_file;
2020
mod metadata;
2121
mod open;
@@ -61,7 +61,7 @@ pub use dir_options::*;
6161
pub use file_type::*;
6262
pub use follow_symlinks::*;
6363
pub use hard_link::*;
64-
pub use is_read_write::is_read_write;
64+
pub use is_file_read_write::is_file_read_write;
6565
pub use metadata::*;
6666
pub use open::*;
6767
pub use open_dir::*;

cap-primitives/src/fs/reopen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Re-open a `fs::File` to produce an independent handle.
22
3-
use crate::fs::{is_read_write, is_same_file, reopen_impl, OpenOptions};
3+
use crate::fs::{is_file_read_write, is_same_file, reopen_impl, OpenOptions};
44
use std::{fs, io};
55

66
/// Re-open an `fs::File` to produce an independent handle.
@@ -11,7 +11,7 @@ use std::{fs, io};
1111
/// cannot be reopened.
1212
#[inline]
1313
pub fn reopen(file: &fs::File, options: &OpenOptions) -> io::Result<fs::File> {
14-
let (read, write) = is_read_write(file)?;
14+
let (read, write) = is_file_read_write(file)?;
1515

1616
// Don't grant more rights than the original file had. And don't allow
1717
// it to create a file.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use posish::fs::is_file_read_write;
2+
use std::{fs, io};
3+
4+
#[inline]
5+
pub(crate) fn is_file_read_write_impl(file: &fs::File) -> io::Result<(bool, bool)> {
6+
is_file_read_write(file)
7+
}

cap-primitives/src/posish/fs/is_read_write_impl.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

cap-primitives/src/posish/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod dir_utils;
88
mod file_path;
99
mod file_type_ext;
1010
mod hard_link_unchecked;
11-
mod is_read_write_impl;
11+
mod is_file_read_write_impl;
1212
mod is_root_dir;
1313
mod is_same_file;
1414
mod metadata_ext;
@@ -87,7 +87,7 @@ pub(crate) use dir_options_ext::*;
8787
pub(crate) use dir_utils::*;
8888
pub(crate) use file_type_ext::*;
8989
pub(crate) use hard_link_unchecked::*;
90-
pub(crate) use is_read_write_impl::*;
90+
pub(crate) use is_file_read_write_impl::*;
9191
pub(crate) use is_root_dir::*;
9292
pub(crate) use is_same_file::*;
9393
pub(crate) use metadata_ext::*;

cap-primitives/src/windows/fs/is_read_write_impl.rs renamed to cap-primitives/src/windows/fs/is_file_read_write_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fs, io, os::windows::io::AsRawHandle};
22

3-
pub(crate) fn is_read_write_impl(file: &fs::File) -> io::Result<(bool, bool)> {
3+
pub(crate) fn is_file_read_write_impl(file: &fs::File) -> io::Result<(bool, bool)> {
44
let handle = file.as_raw_handle();
55
let access_mode = winx::file::query_access_information(handle)?;
66
let read = access_mode.contains(winx::file::AccessMode::FILE_READ_DATA);

cap-primitives/src/windows/fs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod dir_utils;
88
mod file_type_ext;
99
mod get_path;
1010
mod hard_link_unchecked;
11-
mod is_read_write_impl;
11+
mod is_file_read_write_impl;
1212
mod is_same_file;
1313
mod metadata_ext;
1414
mod oflags;
@@ -51,7 +51,7 @@ pub(crate) use dir_options_ext::*;
5151
pub(crate) use dir_utils::*;
5252
pub(crate) use file_type_ext::*;
5353
pub(crate) use hard_link_unchecked::*;
54-
pub(crate) use is_read_write_impl::*;
54+
pub(crate) use is_file_read_write_impl::*;
5555
pub(crate) use is_same_file::*;
5656
pub(crate) use manually::open as open_impl;
5757
pub(crate) use metadata_ext::*;

cap-std/src/fs/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(with_options)]
22
use crate::fs::OpenOptions;
33
use crate::fs::{Metadata, Permissions};
4-
use cap_primitives::fs::is_read_write;
4+
use cap_primitives::fs::is_file_read_write;
55
#[cfg(read_initializer)]
66
use std::io::Initializer;
77
#[cfg(unix)]
@@ -509,7 +509,7 @@ impl fmt::Debug for File {
509509
b.field("fd", &self.std.as_raw_fd());
510510
#[cfg(windows)]
511511
b.field("handle", &self.std.as_raw_handle());
512-
if let Ok((read, write)) = is_read_write(&self.std) {
512+
if let Ok((read, write)) = is_file_read_write(&self.std) {
513513
b.field("read", &read).field("write", &write);
514514
}
515515
b.finish()

0 commit comments

Comments
 (0)