Skip to content

reformat the docs for hidden code in rust sections #29309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions src/doc/trpl/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,73 +269,71 @@ documentation comment, I need to add a little function definition below
it. At the same time, it's just there to satisfy the compiler, so hiding
it makes the example more clear. You can use this technique to explain
longer examples in detail, while still preserving the testability of your
documentation. For example, this code:

```rust
let x = 5;
let y = 6;
println!("{}", x + y);
```

Here's an explanation, rendered:

-------------------------------------------------------------------------------
documentation.

First, we set `x` to five:
For example, imagine that we wanted to document this code:

```rust
let x = 5;
# let y = 6;
# println!("{}", x + y);
```

Next, we set `y` to six:

```rust
# let x = 5;
let y = 6;
# println!("{}", x + y);
```

Finally, we print the sum of `x` and `y`:

```rust
# let x = 5;
# let y = 6;
println!("{}", x + y);
```

-------------------------------------------------------------------------------

Here's the same explanation, in raw text:

-------------------------------------------------------------------------------
We might want the documentation to end up looking like this:

> First, we set `x` to five:
>
> ```text
> ```rust
> let x = 5;
> # let y = 6;
> # println!("{}", x + y);
> ```
>
> Next, we set `y` to six:
>
> ```text
> ```rust
> # let x = 5;
> let y = 6;
> # println!("{}", x + y);
> ```
>
> Finally, we print the sum of `x` and `y`:
>
> ```text
> ```rust
> # let x = 5;
> # let y = 6;
> println!("{}", x + y);
> ```

-------------------------------------------------------------------------------
To keep each code block testable, we want the whole program in each block, but
we don't want the reader to see every line every time. Here's what we put in
our source code:

```text
First, we set `x` to five:

```text
let x = 5;
# let y = 6;
# println!("{}", x + y);
```

Next, we set `y` to six:

```text
# let x = 5;
let y = 6;
# println!("{}", x + y);
```

Finally, we print the sum of `x` and `y`:

```text
# let x = 5;
# let y = 6;
println!("{}", x + y);
```
```

By repeating all parts of the example, you can ensure that your example still
compiles, while only showing the parts that are relevant to that part of your
Expand Down