diff --git a/crates/bin/docs_rs_web/templates/core/about/builds.html b/crates/bin/docs_rs_web/templates/core/about/builds.html index 3c921132c..9080f57b0 100644 --- a/crates/bin/docs_rs_web/templates/core/about/builds.html +++ b/crates/bin/docs_rs_web/templates/core/about/builds.html @@ -32,19 +32,19 @@
To recognize Docs.rs from your Rust code, you can test for the docsrs cfg, e.g.:
- {% filter dedent(None)|highlight("rust") -%}
- #[cfg(docsrs)]
- mod documentation;
+ {% filter highlight("rust") -%}
+#[cfg(docsrs)]
+mod documentation;
{%- endfilter %}
The `docsrs` cfg only applies to the final rustdoc invocation (i.e. the crate currently
being documented). It does not apply to dependencies (including workspace ones).
To recognize Docs.rs from build.rs files, you can test for the environment variable DOCS_RS, e.g.:
- {% filter dedent(3)|highlight("rust") -%}
- if std::env::var("DOCS_RS").is_ok() {
- // ... your code here ...
- }
+ {% filter highlight("rust") -%}
+if std::env::var("DOCS_RS").is_ok() {
+ // ... your code here ...
+}
{%- endfilter %}
This approach can be helpful if you need dependencies for building the library, but not for building the documentation.
You can configure how your crate is built by adding package metadata to your Cargo.toml, e.g.:
- {% filter dedent(None)|highlight("toml") -%}
- [package.metadata.docs.rs]
- rustc-args = ["--cfg", "my_cfg"]
+ {% filter highlight("toml") -%}
+[package.metadata.docs.rs]
+rustc-args = ["--cfg", "my_cfg"]
{%- endfilter %}
Here, the compiler arguments are set so that #[cfg(my_cfg)] (not to be confused with #[cfg(doc)]) can be used for conditional compilation.
This approach is also useful for setting cargo features.