feat(docs): Render Cargo feature-gated code in docs#5967
Open
Mark-Simulacrum wants to merge 1 commit into
Open
feat(docs): Render Cargo feature-gated code in docs#5967Mark-Simulacrum wants to merge 1 commit into
Mark-Simulacrum wants to merge 1 commit into
Conversation
This makes it much nicer to make use of gated functionality (whether unstable or not) because it's visible in the public documentation. It's still clearly marked as gated on the particular feature, so it shouldn't meaningfully increase the risk of usage of unstable surface area.
946191a to
a135832
Compare
jmayclin
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
This makes it much nicer to make use of gated functionality (whether unstable or not) because it's visible in the public documentation. It's still clearly marked as gated on the particular feature, so it shouldn't meaningfully increase the risk of usage of unstable surface area.
How
This uses a few features that are probably new to s2n team:
-Zcrate-attrallows injection of attributes at the crate root from the command line. We use it here to avoid touching the source code with cfg_attr -- but we could replace this with#![cfg_attr(docsrs, feature(doc_cfg))]for example. Happy to do that if we'd prefer the latter.[package.metadata.docs.rs]encodes the configuration for docs.rs builds. package.metadata is a stable namespace for this kind of configuration.Note that docs.rs always uses a (recent-ish) nightly toolchain to build documentation, so we're able to use unstable features there without significant issues. It is possible that these features will change in how to enable them but they've been fairly static for a long time and we would only see issues on a fresh publish (when docs are rebuilt), in the worst case publishing another release that disables this functionality.
Callouts
This enables all features rather than specifying a subset. It's possible we want to hide some of the more internal features (e.g., unstable-testing), but that would require listing out the features.
Testing
Built locally with
cargo docs-rs, see sample output:Related
resolves #4641
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.