From d74b207e39ed9b6ae59116919af65de597b2ee19 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 26 Apr 2026 17:55:45 +0200 Subject: [PATCH] Fix indent of docs.rs build page code example --- .../templates/core/about/builds.html | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 @@

Setting a README

Detecting Docs.rs

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.

@@ -56,9 +56,9 @@

Cross-compiling

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.