Skip to content

Commit 352cc4e

Browse files
authored
More miscellaneous cleanups (#554)
* Change the `dirfd` argument name of the `statx` declaration. * Update the README. * Remove unneeded `&`s in tests and examples. * Add comments describing how to run the benchmarks. * Use `cfg`s consistently in tests. * Don't distribute the benches directory. It isn't needed for users of the crate. * Use top-level comment syntax for a top-level comment. * Remove unneded `#![allow_unsafe]`s. * Add some top-level comments. * Remove unnecessary `.cast()`s.
1 parent f1d44da commit 352cc4e

File tree

31 files changed

+72
-56
lines changed

31 files changed

+72
-56
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository = "https://github.com/bytecodealliance/rustix"
1212
edition = "2018"
1313
keywords = ["api", "file", "network", "safe", "syscall"]
1414
categories = ["os::unix-apis", "date-and-time", "filesystem", "network-programming"]
15-
include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md", "benches"]
15+
include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"]
1616
rust-version = "1.48"
1717

1818
[build-dependencies]

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ conveniences.
2626

2727
`rustix` is low-level and, and while the `net` API supports Winsock2 on
2828
Windows, the rest of the APIs do not support Windows; for higher-level and more
29-
portable APIs built on this functionality, see the [`system-interface`],
30-
[`cap-std`], and [`fs-set-times`] crates, for example.
29+
portable APIs built on this functionality, see the [`cap-std`], [`memfd`],
30+
[`timerfd`], and [`io-streams`] crates, for example.
3131

3232
`rustix` currently has two backends available:
3333

@@ -114,14 +114,14 @@ provides them as free functions rather than associated functions of a `Dir`
114114
type. `rustix`'s `cwd()` function exposes the special `AT_FDCWD` value in a safe
115115
way, so users don't need to open `.` to get a current-directory handle.
116116

117-
`rustix`'s `openat2` function is similar to the [`openat2`] crate, but uses
118-
I/O safety types rather than `RawFd`. `rustix` does not provide dynamic feature
117+
`rustix`'s `openat2` function is similar to the [`openat2`] crate, but uses I/O
118+
safety types rather than `RawFd`. `rustix` does not provide dynamic feature
119119
detection, so users must handle the [`NOSYS`] error themselves.
120120

121-
`rustix`'s `termios` module is similar to the [`termios`] crate, but uses
122-
I/O safety types rather than `RawFd`, and the flags parameters to functions
123-
such as `tcsetattr` are `enum`s rather than bare integers. And, rustix calls
124-
its `tcgetattr` function `tcgetattr`, rather than `Termios::from_fd`.
121+
`rustix`'s `termios` module is similar to the [`termios`] crate, but uses I/O
122+
safety types rather than `RawFd`, and the flags parameters to functions such as
123+
`tcsetattr` are `enum`s rather than bare integers. And, rustix calls its
124+
`tcgetattr` function `tcgetattr`, rather than `Termios::from_fd`.
125125

126126
## Minimum Supported Rust Version (MSRV)
127127

@@ -140,7 +140,6 @@ version of this crate.
140140
[`syscall`]: https://crates.io/crates/syscall
141141
[`sc`]: https://crates.io/crates/sc
142142
[`scall`]: https://crates.io/crates/scall
143-
[`system-interface`]: https://crates.io/crates/system-interface
144143
[`openat`]: https://crates.io/crates/openat
145144
[`openat2`]: https://crates.io/crates/openat2
146145
[`fs-set-times`]: https://crates.io/crates/fs-set-times
@@ -149,6 +148,9 @@ version of this crate.
149148
[`libc`]: https://crates.io/crates/libc
150149
[`windows-sys`]: https://crates.io/crates/windows-sys
151150
[`cap-std`]: https://crates.io/crates/cap-std
151+
[`memfd`]: https://crates.io/crates/memfd
152+
[`timerfd`]: https://crates.io/crates/timerfd
153+
[`io-streams`]: https://crates.io/crates/io-streams
152154
[`bitflags`]: https://crates.io/crates/bitflags
153155
[`Arg`]: https://docs.rs/rustix/latest/rustix/path/trait.Arg.html
154156
[I/O-safe]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md

benches/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
/// Benchmarks for rustix.
2-
///
3-
/// To enable these benchmarks, add `--cfg=criterion` to RUSTFLAGS and enable
4-
/// the "fs", "time", and "process" cargo features.
1+
//! Benchmarks for rustix.
2+
//!
3+
//! To enable these benchmarks, add `--cfg=criterion` to RUSTFLAGS and enable
4+
//! the "fs", "time", and "process" cargo features.
5+
//!
6+
//! ```sh
7+
//! RUSTFLAGS=--cfg=criterion cargo bench --features=fs,time,process
8+
//! ```
59
610
#[cfg(any(
711
not(criterion),
@@ -14,7 +18,7 @@
1418
target_os = "wasi",
1519
))]
1620
fn main() {
17-
unimplemented!()
21+
unimplemented!("Add --cfg=criterion to RUSTFLAGS and enable the \"fs\", \"time\", and \"process\" cargo features.")
1822
}
1923

2024
#[cfg(not(any(

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() -> std::io::Result<()> {
1515
let stdout = rustix::io::stdout();
1616

1717
while !bytes.is_empty() {
18-
match rustix::io::write(&stdout, bytes) {
18+
match rustix::io::write(stdout, bytes) {
1919
// `write` can write fewer bytes than requested. In that case,
2020
// continue writing with the remainder of the bytes.
2121
Ok(n) => bytes = &bytes[n..],

examples/stdio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ fn main() -> io::Result<()> {
2222
let (stdin, stdout, stderr) = (stdin(), stdout(), stderr());
2323

2424
println!("Stdin:");
25-
show(&stdin)?;
25+
show(stdin)?;
2626

2727
println!("Stdout:");
28-
show(&stdout)?;
28+
show(stdout)?;
2929

3030
println!("Stderr:");
31-
show(&stderr)?;
31+
show(stderr)?;
3232

3333
Ok(())
3434
}

src/backend/libc/fs/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ mod sys {
14221422

14231423
weak_or_syscall! {
14241424
pub(super) fn statx(
1425-
pirfd: BorrowedFd<'_>,
1425+
dirfd_: BorrowedFd<'_>,
14261426
path: *const c::c_char,
14271427
flags: c::c_int,
14281428
mask: c::c_uint,

src/backend/libc/process/cpu_set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Rust implementation of the `CPU_*` macro API.
2+
13
#![allow(non_snake_case)]
24

35
use super::super::c;

src/backend/libc/weak.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ unsafe fn fetch(name: &str) -> *mut c_void {
111111
Ok(c_str) => c_str,
112112
Err(..) => return null_mut(),
113113
};
114-
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr().cast())
114+
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr())
115115
}
116116

117117
#[cfg(not(any(target_os = "android", target_os = "linux")))]

src/backend/linux_raw/process/cpu_set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Rust implementation of the `CPU_*` macro API.
2+
13
#![allow(non_snake_case)]
24

35
use super::types::RawCpuSet;

src/backend/linux_raw/runtime/tls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! TLS utilities.
2+
//!
3+
//! # Safety
4+
//!
5+
//! This file contains code that reads the raw phdr array pointed to by the
6+
//! kernel-provided AUXV values.
17
#![allow(unsafe_code)]
28

39
use super::super::c;

0 commit comments

Comments
 (0)