Skip to content

Commit 62479f7

Browse files
authored
Improve documentation generation (#554)
Make `x86_64-unknown-linux-gnu` the default target, as it's more feature rich. Users may not realize that they can select their platform on docs.rs, so it's better to show them more extensive documentation. Don't pass `--cfg docsrs` to rustdoc for docs.rs builds, it's already passed by docs.rs. Generate documentation about supported platforms automatically from the `cfg` attributes.
1 parent 23f7a86 commit 62479f7

File tree

6 files changed

+19
-570
lines changed

6 files changed

+19
-570
lines changed

Cargo.toml

+17-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,23 @@ include = [
2929

3030
[package.metadata.docs.rs]
3131
all-features = true
32-
rustdoc-args = ["--cfg", "docsrs"]
33-
targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"]
32+
default-target = "x86_64-unknown-linux-gnu"
33+
targets = [
34+
"aarch64-apple-ios",
35+
"aarch64-linux-android",
36+
"armv7-linux-androideabi",
37+
"i686-linux-android",
38+
"x86_64-apple-darwin",
39+
"x86_64-pc-solaris",
40+
"x86_64-pc-windows-msvc",
41+
"x86_64-unknown-freebsd",
42+
"x86_64-unknown-fuchsia",
43+
"x86_64-unknown-illumos",
44+
"x86_64-unknown-linux-gnu",
45+
"x86_64-unknown-linux-musl",
46+
"x86_64-unknown-netbsd",
47+
"x86_64-unknown-redox",
48+
]
3449

3550
[package.metadata.playground]
3651
features = ["all"]

src/lib.rs

+2-48
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
//! that are not available on all OSs.
5252
5353
#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
54-
// Show required OS/features on docs.rs.
55-
#![cfg_attr(docsrs, feature(doc_cfg))]
54+
// Automatically generate required OS/features for docs.rs.
55+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5656
// Disallow warnings when running tests.
5757
#![cfg_attr(test, deny(warnings))]
5858
// Disallow warnings in examples.
@@ -266,20 +266,14 @@ impl Type {
266266
///
267267
/// Used for the DCCP protocol.
268268
#[cfg(all(feature = "all", target_os = "linux"))]
269-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
270269
pub const DCCP: Type = Type(sys::SOCK_DCCP);
271270

272271
/// Type corresponding to `SOCK_SEQPACKET`.
273272
#[cfg(all(feature = "all", not(target_os = "espidf")))]
274-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", not(target_os = "espidf")))))]
275273
pub const SEQPACKET: Type = Type(sys::SOCK_SEQPACKET);
276274

277275
/// Type corresponding to `SOCK_RAW`.
278276
#[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))]
279-
#[cfg_attr(
280-
docsrs,
281-
doc(cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf")))))
282-
)]
283277
pub const RAW: Type = Type(sys::SOCK_RAW);
284278
}
285279

@@ -324,7 +318,6 @@ impl Protocol {
324318

325319
/// Protocol corresponding to `DCCP`.
326320
#[cfg(all(feature = "all", target_os = "linux"))]
327-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
328321
pub const DCCP: Protocol = Protocol(sys::IPPROTO_DCCP);
329322

330323
/// Protocol corresponding to `SCTP`.
@@ -364,7 +357,6 @@ impl From<Protocol> for c_int {
364357
///
365358
/// Flags provide additional information about incoming messages.
366359
#[cfg(not(target_os = "redox"))]
367-
#[cfg_attr(docsrs, doc(cfg(not(target_os = "redox"))))]
368360
#[derive(Copy, Clone, Eq, PartialEq)]
369361
pub struct RecvFlags(c_int);
370362

@@ -523,24 +515,6 @@ impl TcpKeepalive {
523515
target_os = "watchos",
524516
target_os = "windows",
525517
))]
526-
#[cfg_attr(
527-
docsrs,
528-
doc(cfg(any(
529-
target_os = "android",
530-
target_os = "dragonfly",
531-
target_os = "freebsd",
532-
target_os = "fuchsia",
533-
target_os = "illumos",
534-
target_os = "ios",
535-
target_os = "visionos",
536-
target_os = "linux",
537-
target_os = "macos",
538-
target_os = "netbsd",
539-
target_os = "tvos",
540-
target_os = "watchos",
541-
target_os = "windows",
542-
)))
543-
)]
544518
pub const fn with_interval(self, interval: Duration) -> Self {
545519
Self {
546520
interval: Some(interval),
@@ -569,26 +543,6 @@ impl TcpKeepalive {
569543
target_os = "watchos",
570544
)
571545
))]
572-
#[cfg_attr(
573-
docsrs,
574-
doc(cfg(all(
575-
feature = "all",
576-
any(
577-
target_os = "android",
578-
target_os = "dragonfly",
579-
target_os = "freebsd",
580-
target_os = "fuchsia",
581-
target_os = "illumos",
582-
target_os = "ios",
583-
target_os = "visionos",
584-
target_os = "linux",
585-
target_os = "macos",
586-
target_os = "netbsd",
587-
target_os = "tvos",
588-
target_os = "watchos",
589-
)
590-
)))
591-
)]
592546
pub const fn with_retries(self, retries: u32) -> Self {
593547
Self {
594548
retries: Some(retries),

0 commit comments

Comments
 (0)