File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,39 @@ in documentation.
8484` #![feature(doc_cfg)] ` feature gate. For more information, see [ its chapter in the Unstable
8585Book] [ unstable-doc-cfg ] and [ its tracking issue] [ issue-doc-cfg ] .
8686
87+ ### ` doc_auto_cfg ` : Automatically generate ` #[doc(cfg)] `
88+
89+ ` doc_auto_cfg ` is an extension to the ` #[doc(cfg)] ` feature. With it, you don't need to add
90+ ` #[doc(cfg(...)] ` anymore unless you want to override the default behaviour. So if we take the
91+ previous source code:
92+
93+ ``` rust
94+ #![feature(doc_auto_cfg)]
95+
96+ /// Token struct that can only be used on Windows.
97+ #[cfg(any(windows, doc))]
98+ pub struct WindowsToken ;
99+
100+ /// Token struct that can only be used on Unix.
101+ #[cfg(any(unix, doc))]
102+ pub struct UnixToken ;
103+
104+ /// Token struct that is only available with the `serde` feature
105+ #[cfg(feature = " serde" )]
106+ #[derive(serde:: Deserialize )]
107+ pub struct SerdeToken ;
108+ ```
109+
110+ It'll render almost the same, the difference being that ` doc ` will also be displayed. To fix this,
111+ you can use ` doc_cfg_hide ` :
112+
113+ ``` rust
114+ #![feature(doc_cfg_hide)]
115+ #![doc(cfg_hide(doc))]
116+ ```
117+
118+ And ` doc ` won't show up anymore!
119+
87120[ cfg-doc ] : ./advanced-features.md
88121[ unstable-doc-cfg ] : ../unstable-book/language-features/doc-cfg.html
89122[ issue-doc-cfg ] : https://github.com/rust-lang/rust/issues/43781
You can’t perform that action at this time.
0 commit comments