Move doc comments into a future section about creating a library

This commit is contained in:
Carol (Nichols || Goulding) 2016-07-30 16:13:51 -04:00
parent 1e7e0e61c4
commit b5ebd97046
3 changed files with 48 additions and 41 deletions

View File

@ -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]()

View File

@ -37,43 +37,3 @@ fn main() {
```
Thats all there is to it. Comments are not particularly complicated.
## Documentation comments
However, Rust has another kind of comment: a documentation comment. These
comments dont affect the way that the code works, but they do work with Rusts
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 doesnt 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?
^~~~~~~~~~~~~~~~~~~~~~~~~~
```

View File

@ -0,0 +1,45 @@
## Documentation
<!-- Insert why documentation is important here, who your audience is for documentation -->
### Documentation comments
Rust has another kind of comment: a documentation comment. These
comments dont affect the way that the code works, but they do work with Rusts
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 doesnt 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