我想记录一下我的箱子,并在文档中包括一个表格:
//! Demonstrating MarkDown tables.
//!
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president | I can't think of any more "funny" things | oopsie |
//!使用cargo doc呈现此结果如下:

这就是我想要的。但是,您可能已经注意到,只有一个源代码行非常长。事实上,超过100个字符的长度。就像许多锈蚀项目一样,我想把我所有的线条保持在100个字符以下。所以我设法打破了界限。
所有这些版本:
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president
//! I can't think of any more "funny" things | oopsie |
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president |
//! I can't think of any more "funny" things | oopsie |
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president
//! | I can't think of any more "funny" things | oopsie |
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president |
//! | I can't think of any more "funny" things | oopsie |
//! | Foo | Bar | Baz | Qux |
//! | --- | --- | --- | --- |
//! | Hail the turbofish `::<>` | Ferris for president \
//! I can't think of any more "funny" things | oopsie |在以下方面的成果:

文档中有哪些选项可以在不违反行长限制的情况下包括长表行?
发布于 2019-03-30 15:37:36
HTML
正如Francis已经回答的那样,如果您想保持短行,就必须使用HTML。rustdoc利用拉下标记,并且不支持您想要的东西。
包括外部文件
夜间&医生
跟踪问题: rfc 1990 -向rustc添加外部doc属性。在nightly工具链的情况下,您可以启用external_doc特性,并在#[doc(include = "../some/path")]中包含外部Markdown文件。
需要注意的是,无论在哪个模块中使用#[doc(include = "...")],路径都是相对于板条根的总是 (lib.rs,main.rs,.)。
示例:
.
|____Cargo.toml
|____Cargo.lock
|____doc
| |____foo-bar-bar.md
|____src
| |____main-hallo.md
| |____foo
| | |____mod.rs
| | |____bar.rs
| |____main.rssrc/main.rs
#![feature(external_doc)]
pub mod foo;
#[doc(include = "main-hallo.md")]
pub fn hallo() {}
fn main() {}src/foo/bar.rs
#[doc(include = "../doc/foo-bar-bar.md")]
pub struct Bar;您可以在src/文件夹中保存单独的Markdown文档,也可以将其保存在单独的文件夹中,如doc/等。但是路径总是相对于板条根。
夜间及rdoc
还有rdoc编译器插件(需要nightly),它基本上可以做同样的事情。如何启用和使用它将在项目README.md中描述。
稳定
为了稳定,我会做以下几件事:
build.rs,它将扫描.md文件并将其输出为.rs文件(内容相同,只需在行前面加上///或//!)、std::env::var("OUT_DIR")文件夹中,
include!(concat!(env!("OUT_DIR"), "/main-hallo-md.rs"));。
夜间沙沙
有comment_width选项(默认为80) & wrap_comments选项(默认为false)。这可以帮助您将注释保持到一定的宽度。但是我用长标记表行试了一下,它把它包装成->坏了的表。别用它。
发布于 2019-03-24 15:23:15
使用HTML标记。
//! Demonstrating HTML tables.
//!
//! <table>
//! <thead>
//! <tr>
//! <th>Foo</th>
//! <th>Bar</th>
//! <th>Baz</th>
//! <th>Quux</th>
//! </tr>
//! </thead>
//! <tbody>
//! <tr>
//! <td>Hail the turbofish <code>::<></code></td>
//! <td>Ferris for president </td>
//! <td>
//! I can't think of any
//! more "funny" things
//! </td>
//! <td>oopsie</td>
//! </tr>
//! </tbody>
//! </table>https://stackoverflow.com/questions/55324887
复制相似问题