rustdoc

How to include ASCII art/diagrams in Rust source-code comment documentation?

霸气de小男生 提交于 2020-01-15 04:00:21
问题 How should Markdown be used with rustdoc to include diagrams or ASCII art? From reading the manual, triple back-ticks can be used for code-snippets. How do I include literal, non-formatted text? (Something like Doxygen's <pre>...</pre> ) 回答1: You use triple graves ```text like this ``` Note the text . This tells rustdoc to not syntax highlight what's inside; the default is to think it's Rust code. 来源: https://stackoverflow.com/questions/40550665/how-to-include-ascii-art-diagrams-in-rust

How to generate documentation for private items

痞子三分冷 提交于 2019-12-22 05:14:50
问题 I have a project with: main.rs module_1/mod.rs module_2/mod.rs module_2/module_3/mod.rs when I run cargo doc , I have just documentation for main.rs , not for modules. In my main.rs I have: mod module_1; mod module_2; fn main() { ... } I have tried documenting modules using /// or //! . I can't find in rustdoc 's help how do that. Somebody can explain me? 回答1: This is because those modules are private, and the default behavior is to document public members only. As of Rust 1.29.0, cargo doc

How do you handle the “could not parse code block as Rust code” rustdoc warning?

折月煮酒 提交于 2019-12-20 06:19:07
问题 I'm writing some rust doc examples (that are compiling): /// ```rust /// # #[macro_use] /// # extern crate ... /// ... /// ``` But cargo doc gives me this [incorrect] warning: warning: could not parse code block as Rust code --> srml/support/src/dispatch.rs:105:5 | 105 | /// ```rust | ________^ 106 | | /// # #[macro_use] | |_ | = note: error from rustc: unknown start of token: ` help: mark blocks that do not contain Rust code as text | 105 | /// ```textrust | ^^^^^^^ Should I just suppress

Is there a way to hide a macro pattern from docs?

半世苍凉 提交于 2019-12-08 15:44:53
问题 As of Rust 1.6.0, the generated documentation hides the implementation of each macro pattern: Is there a way to hide some of the patterns from the Cargo-generated docs? macro_rules! mc { // hide this entire pattern (@impl, $arg:expr) => { 42 + $arg }; // but not this one ($arg:expr) => { mc!(@impl, $arg) }; } 回答1: I guess this is the optimum solution: /// Not meant to be called directly #[doc(hidden)] #[macro_export] macro_rules! hidden { ( $hidden_rule1:expr ) => { ... }; ( $hidden_rule2

How would one achieve conditional compilation with Rust projects that have doctests?

淺唱寂寞╮ 提交于 2019-12-04 04:45:25
问题 I've used conditional compilation to change the type signature of a function, and now the same doctest can't be run for both "feature" modes, so I need a way to opt-out of the doctests. I've tried merging #[cfg_attr(feature = "rss_loose", ignore)] used in normal tests and ///rust,ignore to make ///rust,cfg_attr(feature = "rss_loose", ignore) but this doesn't seem to work. 回答1: Just write two different sets of documentation and tests and it will all work as-is: /// ``` /// assert_eq!(42, dt:

How is it possible to keep Rust module documentation in separate Markdown files?

我的梦境 提交于 2019-12-02 05:03:20
问题 This section of the Rust book seems to imply that it is possible to keep Rust documentation in separate .md files, but it does not say how these .md files can then be included back. How does this work? 回答1: It doesn't. That section on describing the functionality of rustdoc is saying that it can process individual .md files. The third paragraph touches on this: Documentation can be generated in two ways: from source code, and from standalone Markdown files. Insofar as I am aware, there is no

How would one achieve conditional compilation with Rust projects that have doctests?

心已入冬 提交于 2019-12-02 01:31:09
I've used conditional compilation to change the type signature of a function, and now the same doctest can't be run for both "feature" modes, so I need a way to opt-out of the doctests. I've tried merging #[cfg_attr(feature = "rss_loose", ignore)] used in normal tests and ///rust,ignore to make ///rust,cfg_attr(feature = "rss_loose", ignore) but this doesn't seem to work. Just write two different sets of documentation and tests and it will all work as-is: /// ``` /// assert_eq!(42, dt::foo()); /// ``` #[cfg(not(feature = "alternate"))] pub fn foo() -> u8 { 42 } /// ``` /// assert_eq!(true, dt: