Skip to content

Commit a25ae26

Browse files
authored
Miscellaneous documentation cleanups. (#778)
1 parent 5d9bcbc commit a25ae26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+171
-144
lines changed

examples/dup2_to_replace_stdio.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
fn main() -> std::io::Result<()> {
66
use rustix::pipe::pipe;
77
use rustix::stdio::{dup2_stdin, dup2_stdout};
8-
use std::io::{BufRead, BufReader};
98

109
// Create some new file descriptors that we'll use to replace stdio's file
1110
// descriptors with.
1211
let (reader, writer) = pipe()?;
1312

14-
// Use `dup2` to copy our new file descriptors over the stdio file descriptors.
13+
// Use `dup2` to copy our new file descriptors over the stdio file
14+
// descriptors.
1515
//
16-
// Rustix has a plain `dup2` function too, but it requires a `&mut OwnedFd`,
17-
// so these helper functions make it easier to use when replacing stdio fds.
16+
// Rustix has a plain `dup2` function too, but it requires a
17+
// `&mut OwnedFd`, so these helper functions make it easier to use when
18+
// replacing stdio fds.
1819
dup2_stdin(&reader)?;
1920
dup2_stdout(&writer)?;
2021

@@ -28,9 +29,9 @@ fn main() -> std::io::Result<()> {
2829

2930
// And we can read from stdin, and it'll read from our pipe. It's a little
3031
// silly that we connected our stdout to our own stdin, but it's just an
31-
// example :-).
32+
// example 😀.
3233
let mut s = String::new();
33-
BufReader::new(std::io::stdin()).read_line(&mut s)?;
34+
std::io::stdin().read_line(&mut s)?;
3435
assert_eq!(s, "hello, world!\n");
3536

3637
Ok(())

src/backend/libc/c.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Libc and supplemental types and constants.
2+
13
#![allow(unused_imports)]
24

35
// Import everything from libc, but we'll add some stuff and override some

src/backend/libc/event/epoll.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ pub fn create(flags: CreateFlags) -> io::Result<OwnedFd> {
160160
unsafe { ret_owned_fd(c::epoll_create1(bitflags_bits!(flags))) }
161161
}
162162

163-
/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an
164-
/// epoll object.
163+
/// `epoll_ctl(self, EPOLL_CTL_ADD, data, event)`—Adds an element to an epoll
164+
/// object.
165165
///
166-
/// This registers interest in any of the events set in `events` occurring
167-
/// on the file descriptor associated with `data`.
166+
/// This registers interest in any of the events set in `events` occurring on
167+
/// the file descriptor associated with `data`.
168168
///
169169
/// If [`delete`] is not called on the I/O source passed into this function
170170
/// before the I/O source is `close`d, then the `epoll` will act as if the I/O
@@ -198,8 +198,8 @@ pub fn add(
198198
}
199199
}
200200

201-
/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in
202-
/// a given epoll object.
201+
/// `epoll_ctl(self, EPOLL_CTL_MOD, target, event)`—Modifies an element in a
202+
/// given epoll object.
203203
///
204204
/// This sets the events of interest with `target` to `events`.
205205
#[doc(alias = "epoll_ctl")]
@@ -229,8 +229,8 @@ pub fn modify(
229229
}
230230
}
231231

232-
/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in
233-
/// a given epoll object.
232+
/// `epoll_ctl(self, EPOLL_CTL_DEL, target, NULL)`—Removes an element in a
233+
/// given epoll object.
234234
#[doc(alias = "epoll_ctl")]
235235
pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
236236
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
@@ -341,8 +341,8 @@ impl EventData {
341341

342342
/// Return the value as a `u64`.
343343
///
344-
/// If the stored value was a pointer, the pointer is zero-extended to
345-
/// a `u64`.
344+
/// If the stored value was a pointer, the pointer is zero-extended to a
345+
/// `u64`.
346346
#[inline]
347347
pub fn u64(self) -> u64 {
348348
unsafe { self.as_u64 }

src/backend/libc/event/poll_fd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'fd> PollFd<'fd> {
112112
/// Returns the ready events.
113113
#[inline]
114114
pub fn revents(&self) -> PollFlags {
115-
// Use `unwrap()` here because in theory we know we know all the bits
115+
// Use `.unwrap()` here because in theory we know we know all the bits
116116
// the OS might set here, but OS's have added extensions in the past.
117117
PollFlags::from_bits(self.pollfd.revents).unwrap()
118118
}
@@ -123,7 +123,7 @@ impl<'fd> AsFd for PollFd<'fd> {
123123
#[inline]
124124
fn as_fd(&self) -> BorrowedFd<'_> {
125125
// SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
126-
// valid for the `fd lifetime.
126+
// valid for the `'fd` lifetime.
127127
unsafe { BorrowedFd::borrow_raw(self.pollfd.fd) }
128128
}
129129
}
@@ -133,7 +133,7 @@ impl<'fd> AsSocket for PollFd<'fd> {
133133
#[inline]
134134
fn as_socket(&self) -> BorrowedFd<'_> {
135135
// SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
136-
// valid for the `fd lifetime.
136+
// valid for the `'fd` lifetime.
137137
unsafe { BorrowedFd::borrow_raw(self.pollfd.fd as RawFd) }
138138
}
139139
}

src/backend/libc/fs/inotify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub fn inotify_add_watch<P: crate::path::Arg>(
112112

113113
/// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify
114114
///
115-
/// The watch descriptor provided should have previously been returned
116-
/// by [`inotify_add_watch`] and not previously have been removed.
115+
/// The watch descriptor provided should have previously been returned by
116+
/// [`inotify_add_watch`] and not previously have been removed.
117117
#[doc(alias = "inotify_rm_watch")]
118118
pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> {
119119
// Android's `inotify_rm_watch` takes `u32` despite that

src/backend/libc/fs/makedev.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
3030
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
3131
#[inline]
3232
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
33-
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit,
34-
// so we do it ourselves.
33+
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do
34+
// it ourselves.
3535
((u64::from(maj) & 0xffff_f000_u64) << 32)
3636
| ((u64::from(maj) & 0x0000_0fff_u64) << 8)
3737
| ((u64::from(min) & 0xffff_ff00_u64) << 12)
@@ -86,8 +86,8 @@ pub(crate) fn major(dev: Dev) -> u32 {
8686
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
8787
#[inline]
8888
pub(crate) fn major(dev: Dev) -> u32 {
89-
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit,
90-
// so we do it ourselves.
89+
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do
90+
// it ourselves.
9191
(((dev >> 31 >> 1) & 0xffff_f000) | ((dev >> 8) & 0x0000_0fff)) as u32
9292
}
9393

@@ -125,8 +125,8 @@ pub(crate) fn minor(dev: Dev) -> u32 {
125125
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
126126
#[inline]
127127
pub(crate) fn minor(dev: Dev) -> u32 {
128-
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit,
129-
// so we do it ourselves.
128+
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do
129+
// it ourselves.
130130
(((dev >> 12) & 0xffff_ff00) | (dev & 0x0000_00ff)) as u32
131131
}
132132

src/backend/libc/fs/syscalls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF
128128
return open_via_syscall(path, oflags, mode);
129129
}
130130

131-
// On these platforms, `mode_t` is `u16` and can't be passed directly to
132-
// a variadic function.
131+
// On these platforms, `mode_t` is `u16` and can't be passed directly to a
132+
// variadic function.
133133
#[cfg(any(
134134
apple,
135135
freebsdlike,
@@ -191,8 +191,8 @@ pub(crate) fn openat(
191191
return openat_via_syscall(dirfd, path, oflags, mode);
192192
}
193193

194-
// On these platforms, `mode_t` is `u16` and can't be passed directly to
195-
// a variadic function.
194+
// On these platforms, `mode_t` is `u16` and can't be passed directly to a
195+
// variadic function.
196196
#[cfg(any(
197197
apple,
198198
freebsdlike,

src/backend/libc/fs/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ bitflags! {
249249
const WRONLY = bitcast!(c::O_WRONLY);
250250

251251
/// `O_RDWR`
252+
///
253+
/// This is not equal to `RDONLY | WRONLY`. It's a distinct flag.
252254
const RDWR = bitcast!(c::O_RDWR);
253255

254256
/// `O_NOCTTY`

src/backend/libc/time/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub(crate) fn clock_gettime(id: ClockId) -> Timespec {
109109
clock_gettime_old(id)
110110
}
111111

112-
// Use `unwrap()` here because `clock_getres` can fail if the clock itself
112+
// Use `.unwrap()` here because `clock_getres` can fail if the clock itself
113113
// overflows a number of seconds, but if that happens, the monotonic clocks
114114
// can't maintain their invariants, or the realtime clocks aren't properly
115115
// configured.

src/backend/libc/time/types.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ pub type Itimerspec = c::itimerspec;
2525
/// [`timerfd_settime`]: crate::time::timerfd_settime
2626
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
2727
#[cfg(fix_y2038)]
28-
#[allow(missing_docs)]
2928
#[repr(C)]
3029
#[derive(Debug, Clone)]
3130
pub struct Itimerspec {
31+
/// The interval of an interval timer.
3232
pub it_interval: Timespec,
33+
/// Time remaining in the current interval.
3334
pub it_value: Timespec,
3435
}
3536

@@ -116,10 +117,10 @@ bitflags! {
116117
pub enum TimerfdClockId {
117118
/// `CLOCK_REALTIME`—A clock that tells the “real” time.
118119
///
119-
/// This is a clock that tells the amount of time elapsed since the
120-
/// Unix epoch, 1970-01-01T00:00:00Z. The clock is externally settable, so
121-
/// it is not monotonic. Successive reads may see decreasing times, so it
122-
/// isn't reliable for measuring durations.
120+
/// This is a clock that tells the amount of time elapsed since the Unix
121+
/// epoch, 1970-01-01T00:00:00Z. The clock is externally settable, so it is
122+
/// not monotonic. Successive reads may see decreasing times, so it isn't
123+
/// reliable for measuring durations.
123124
Realtime = bitcast!(c::CLOCK_REALTIME),
124125

125126
/// `CLOCK_MONOTONIC`—A clock that tells an abstract time.

0 commit comments

Comments
 (0)