From b5ebd970460a38e9014e026d8f0a0ababc3b6646 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Sat, 30 Jul 2016 16:13:51 -0400 Subject: [PATCH] Move doc comments into a future section about creating a library --- src/SUMMARY.md | 4 +++- src/ch03-06-comments.md | 40 -------------------------------- src/chYY-YY-documentation.md | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 src/chYY-YY-documentation.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 864c33f8a..1edbc1468 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -81,8 +81,10 @@ - [Using Rust from Other Languages]() - [`static`]() -- [Cargo]() +- [Creating a Library]() + - [Cargo]() - [Crates.io]() + - [Documentation](chYY-YY-documentation.md) - [Advanced Type System Features]() - [Associated Types]() diff --git a/src/ch03-06-comments.md b/src/ch03-06-comments.md index 7a96ae381..88995480d 100644 --- a/src/ch03-06-comments.md +++ b/src/ch03-06-comments.md @@ -37,43 +37,3 @@ fn main() { ``` That’s all there is to it. Comments are not particularly complicated. - -## Documentation comments - -However, Rust has another kind of comment: a documentation comment. These -comments don’t affect the way that the code works, but they do work with Rust’s -tools. More specifically, the `rustdoc` tool that comes with Rust reads -documentation comments and produces HTML documentation from them. - -Documentation comments use an extra slash: - -```rust -/// The foo function doesn’t really do much. -fn foo() { -} - -/// We also can use -/// multiple comments here too, -/// like we did before -fn bar() { -} -``` - -This comment would then be interpreted by `rustdoc` as documenting the thing -that follows it: `foo()` and `bar()`. - -Because documentation comments have semantic meaning to `rustdoc`, the compiler -will pay attention to the placement of your documentation comments. For -example, a program with only this: - -```rust,ignore -/// What am I documenting? -``` - -Will give a compiler error: - -```text -src/main.rs:1:1: 1:27 error: expected item after doc comment -src/main.rs:1 /// What am I documenting? - ^~~~~~~~~~~~~~~~~~~~~~~~~~ -``` diff --git a/src/chYY-YY-documentation.md b/src/chYY-YY-documentation.md new file mode 100644 index 000000000..1adb89e9d --- /dev/null +++ b/src/chYY-YY-documentation.md @@ -0,0 +1,45 @@ +## Documentation + + + +### Documentation comments + +Rust has another kind of comment: a documentation comment. These +comments don’t affect the way that the code works, but they do work with Rust’s +tools. More specifically, the `rustdoc` tool that comes with Rust reads +documentation comments and produces HTML documentation from them. + +Documentation comments use an extra slash: + +```rust +/// The foo function doesn’t really do much. +fn foo() { +} + +/// We also can use +/// multiple comments here too, +/// like we did before +fn bar() { +} +``` + +This comment would then be interpreted by `rustdoc` as documenting the thing +that follows it: `foo()` and `bar()`. + +Because documentation comments have semantic meaning to `rustdoc`, the compiler +will pay attention to the placement of your documentation comments. For +example, a program with only this: + +```rust,ignore +/// What am I documenting? +``` + +Will give a compiler error: + +```text +src/main.rs:1:1: 1:27 error: expected item after doc comment +src/main.rs:1 /// What am I documenting? + ^~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +### Generating HTML documentation