Skip to content

Commit e2311e6

Browse files
authored
docs: Expose feature-gated APIs with doc(cfg) (#346)
APIs hidden behind features can now be viewed on docs.rs! All feature-gated modules and structs should be annotated with a note that mentions the specific feature flag needed to use the corresponding API. This primarily fixes a linter warning regarding a link to a nonexistent integration which was gated behind a feature. There are other small fixes as well, mostly just hooking up links that weren't assigned destinations. While the doc feature is considered unstable, we're taking advantage of the fact that docs are built with nightly by default.
1 parent b4b8763 commit e2311e6

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

sentry/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ Sentry (getsentry.com) client for rust ;)
1212
edition = "2018"
1313
autoexamples = true
1414

15+
# To build locally:
16+
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --open
1517
[package.metadata.docs.rs]
1618
all-features = true
19+
# Defines the configuration attribute `doc_cfg` in order to expose feature-gated docs.
20+
rustdoc-args = ["--cfg", "doc_cfg"]
1721

1822
[features]
1923
default = ["backtrace", "contexts", "panic", "transport"]

sentry/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]
105105
#![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")]
106106
#![warn(missing_docs)]
107+
// Only enables the `doc_cfg` feature when the `doc_cfg` configuration attribute
108+
// is defined. Used to expose docs for feature-locked integrations, and other
109+
// feature-gated documentation.
110+
#![cfg_attr(doc_cfg, feature(doc_cfg))]
107111

108112
mod defaults;
109113
mod init;
@@ -171,27 +175,35 @@ pub use crate::init::{init, ClientInitGuard};
171175
/// [`apply_defaults()`]: ../fn.apply_defaults.html
172176
pub mod integrations {
173177
#[cfg(feature = "anyhow")]
178+
#[cfg_attr(doc_cfg, doc(cfg(feature = "anyhow")))]
174179
#[doc(inline)]
175180
pub use sentry_anyhow as anyhow;
176181
#[cfg(feature = "backtrace")]
182+
#[cfg_attr(doc_cfg, doc(cfg(feature = "backtrace")))]
177183
#[doc(inline)]
178184
pub use sentry_backtrace as backtrace;
179185
#[cfg(feature = "contexts")]
186+
#[cfg_attr(doc_cfg, doc(cfg(feature = "contexts")))]
180187
#[doc(inline)]
181188
pub use sentry_contexts as contexts;
182189
#[cfg(feature = "debug-images")]
190+
#[cfg_attr(doc_cfg, doc(cfg(feature = "debug_images")))]
183191
#[doc(inline)]
184192
pub use sentry_debug_images as debug_images;
185193
#[cfg(feature = "log")]
194+
#[cfg_attr(doc_cfg, doc(cfg(feature = "log")))]
186195
#[doc(inline)]
187196
pub use sentry_log as log;
188197
#[cfg(feature = "panic")]
198+
#[cfg_attr(doc_cfg, doc(cfg(feature = "panic")))]
189199
#[doc(inline)]
190200
pub use sentry_panic as panic;
191201
#[cfg(feature = "slog")]
202+
#[cfg_attr(doc_cfg, doc(cfg(feature = "slog")))]
192203
#[doc(inline)]
193204
pub use sentry_slog as slog;
194205
#[cfg(feature = "tracing")]
206+
#[cfg_attr(doc_cfg, doc(cfg(feature = "tracing")))]
195207
#[doc(inline)]
196208
pub use sentry_tracing as tracing;
197209
}

sentry/src/transports/curl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use crate::{sentry_debug, types::Scheme, ClientOptions, Envelope, Transport};
99

1010
/// A [`Transport`] that sends events via the [`curl`] library.
1111
///
12-
/// This is enabled by the `curl` flag.
12+
/// This is enabled by the `curl` feature flag.
13+
///
14+
/// [`curl`]: https://crates.io/crates/curl
15+
#[cfg_attr(doc_cfg, doc(cfg(feature = "curl")))]
1316
pub struct CurlHttpTransport {
1417
thread: TransportThread,
1518
}

sentry/src/transports/reqwest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use crate::{sentry_debug, ClientOptions, Envelope, Transport};
1010
///
1111
/// When the `transport` feature is enabled this will currently
1212
/// be the default transport. This is separately enabled by the
13-
/// `reqwest` flag.
13+
/// `reqwest` feature flag.
14+
///
15+
/// [`reqwest`]: https://crates.io/crates/reqwest
16+
#[cfg_attr(doc_cfg, doc(cfg(feature = "reqwest")))]
1417
pub struct ReqwestHttpTransport {
1518
thread: TransportThread,
1619
}

sentry/src/transports/surf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::{sentry_debug, ClientOptions, Envelope, Transport};
88

99
/// A [`Transport`] that sends events via the [`surf`] library.
1010
///
11-
/// This is enabled by the `surf` flag.
11+
/// This is enabled by the `surf` feature flag.
12+
///
13+
/// [`surf`]: https://crates.io/crates/surf
14+
#[cfg_attr(doc_cfg, doc(cfg(feature = "surf")))]
1215
pub struct SurfHttpTransport {
1316
thread: TransportThread,
1417
}

0 commit comments

Comments
 (0)