Skip to content

Commit cc673a1

Browse files
authored
Improve comments and documentation. (#1332)
1 parent 4d062ac commit cc673a1

54 files changed

Lines changed: 207 additions & 151 deletions

Some content is hidden

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

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ targets = [
110110
default = ["std", "use-libc-auxv"]
111111

112112
# This enables use of std. Disabling this enables `#![no_std]`, and requires
113-
# Rust 1.64 or newer.
113+
# Rust 1.77 or newer.
114114
std = ["bitflags/std", "alloc", "libc?/std", "libc_errno?/std"]
115115

116116
# Enable this to request the libc backend.
@@ -172,6 +172,9 @@ system = ["linux-raw-sys/system"]
172172
runtime = ["linux-raw-sys/prctl"]
173173

174174
# Enable all API features.
175+
#
176+
# This is primarily intended for rustix developers. Users are encouraged to
177+
# enable only those features they need.
175178
all-apis = [
176179
"event",
177180
"fs",

src/backend/libc/fs/dir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ impl DirEntry {
330330
&self.name
331331
}
332332

333-
/// Returns the "offset" of this directory entry. Note that this is not
334-
/// a true numerical offset but an opaque cookie that identifies a
335-
/// position in the given stream.
333+
/// Returns the offset of this directory entry. This is not a true
334+
/// numerical offset but an opaque cookie that identifies a position in the
335+
/// given stream.
336336
#[cfg(any(
337337
linux_like,
338338
solarish,

src/backend/libc/fs/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ fn times_to_attrlist(times: &Timestamps) -> io::Result<(c::size_t, [c::timespec;
22672267
#[cfg(apple)]
22682268
type Attrgroup = u32;
22692269

2270-
/// Attribute list for use with `setattrlist`.
2270+
/// Attribute list for use with [`setattrlist`].
22712271
#[cfg(apple)]
22722272
#[repr(C)]
22732273
struct Attrlist {

src/backend/libc/fs/types.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,17 @@ bitflags! {
332332

333333
/// `O_LARGEFILE`
334334
///
335-
/// Note that rustix and/or libc will automatically set this flag when appropriate on
336-
/// `open(2)` and friends, thus typical users do not need to care about it.
337-
/// It will may be reported in return of `fcntl_getfl`, though.
335+
/// Rustix and/or libc will automatically set this flag when
336+
/// appropriate in the [`rustix::fs::open`] family of functions, so
337+
/// typical users do not need to care about it. It may be reported in
338+
/// the return of `fcntl_getfl`, though.
338339
#[cfg(any(linux_kernel, solarish))]
339340
const LARGEFILE = bitcast!(c::O_LARGEFILE);
340341

341342
/// `O_ASYNC`, `FASYNC`
342343
///
343-
/// Note that this flag can't be used with [`rustix::fs::open`] family of functions, use
344-
/// [`rustix::fs::fcntl_setfl`] instead
344+
/// This flag can't be used with the [`rustix::fs::open`] family of
345+
/// functions, use [`rustix::fs::fcntl_setfl`] instead.
345346
#[cfg(not(any(
346347
target_os = "aix",
347348
target_os = "espidf",
@@ -994,7 +995,7 @@ pub type StatFs = c::statfs;
994995
#[cfg(linux_like)]
995996
pub type StatFs = c::statfs64;
996997

997-
/// `fsid_t` for use with `StatFs`.
998+
/// `fsid_t` for use with [`StatFs`].
998999
#[cfg(not(any(
9991000
solarish,
10001001
target_os = "espidf",

src/backend/libc/mount/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(crate) enum FsConfigCmd {
147147
/// `FSCONFIG_CMD_RECONFIGURE`
148148
Reconfigure = 7,
149149

150-
/// `FSCONFIG_CMD_CREATE_EXCL`
150+
/// `FSCONFIG_CMD_CREATE_EXCL` (since Linux 6.6)
151151
CreateExclusive = 8,
152152
}
153153

src/backend/libc/net/addr.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ impl SocketAddrUnix {
7979
/// Construct a new unnamed address.
8080
///
8181
/// The kernel will assign an abstract Unix-domain address to the socket
82-
/// when you call [`bind_unix()`][crate::net::bind_unix]. You can
83-
/// inspect the assigned name with
84-
/// [`getsockname`][crate::net::getsockname].
82+
/// when you call [`bind`][crate::net::bind]. You can inspect the assigned
83+
/// name with [`getsockname`][crate::net::getsockname].
8584
///
8685
/// # References
8786
/// - [Linux]
@@ -238,6 +237,9 @@ impl fmt::Debug for SocketAddrUnix {
238237
}
239238

240239
/// `struct sockaddr_storage`.
240+
///
241+
/// This type is guaranteed to be large enough to hold any encoded socket
242+
/// address.
241243
#[repr(transparent)]
242244
#[derive(Copy, Clone)]
243245
pub struct SocketAddrStorage(c::sockaddr_storage);

src/backend/libc/net/read_sockaddr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) unsafe fn read_sa_family(storage: *const c::sockaddr) -> u16 {
101101
#[cfg(apple)]
102102
#[inline]
103103
unsafe fn read_sun_path0(storage: *const c::sockaddr) -> u8 {
104-
// In `read_ss_family` we assert that we know the layout of `sockaddr`.
104+
// In `read_sa_family` we assert that we know the layout of `sockaddr`.
105105
storage
106106
.cast::<u8>()
107107
.add(super::addr::offsetof_sun_path())

src/backend/libc/net/sockopt.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
10861086
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
10871087

10881088
if optlen as usize == size_of::<c::xdp_mmap_offsets_v1>() {
1089-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1090-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1089+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
1090+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
10911091
let xpd_mmap_offsets = unsafe { value.assume_init() };
10921092
Ok(XdpMmapOffsets {
10931093
rx: XdpRingOffset {
@@ -1121,8 +1121,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
11211121
size_of::<xdp_mmap_offsets>(),
11221122
"unexpected getsockopt size"
11231123
);
1124-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1125-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1124+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
1125+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
11261126
let xpd_mmap_offsets = unsafe { value.assume_init() };
11271127
Ok(XdpMmapOffsets {
11281128
rx: XdpRingOffset {
@@ -1165,8 +1165,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11651165
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
11661166

11671167
if optlen as usize == size_of::<xdp_statistics_v1>() {
1168-
// Safety: All members of xdp_statistics are u64 and thus are correctly
1169-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1168+
// SAFETY: All members of xdp_statistics are `u64` and thus are
1169+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
11701170
let xdp_statistics = unsafe { value.assume_init() };
11711171
Ok(XdpStatistics {
11721172
rx_dropped: xdp_statistics.rx_dropped,
@@ -1182,8 +1182,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11821182
size_of::<xdp_statistics>(),
11831183
"unexpected getsockopt size"
11841184
);
1185-
// Safety: All members of xdp_statistics are u64 and thus are correctly
1186-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1185+
// SAFETY: All members of xdp_statistics are `u64` and thus are
1186+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
11871187
let xdp_statistics = unsafe { value.assume_init() };
11881188
Ok(XdpStatistics {
11891189
rx_dropped: xdp_statistics.rx_dropped,

src/backend/libc/system/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> {
8383
}
8484
}
8585

86-
// https://github.com/rust-lang/libc/pull/4212
86+
// <https://github.com/rust-lang/libc/pull/4212>
8787
#[cfg(target_os = "android")]
8888
pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> {
8989
syscall! {

src/backend/libc/termios/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Types for the `termios` module.
2+
13
#![allow(non_camel_case_types)]
24

35
#[cfg(not(target_os = "redox"))]

0 commit comments

Comments
 (0)