Skip to content
Closed

fix doc #24837

Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions src/doc/trpl/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ In `Character`, for instance, `Digit` gives a meaningful name for an `i32`
value, where `Other` is only a name. However, the fact that they represent
distinct categories of `Character` is a very useful property.

We use the `::` syntax to use the name of each variant: They’re scoped by the name
of the `enum` itself. This allows both of these to work:

```rust,ignore
Character::Digit(10);
Hand::Digit;
```

Both variants are named `Digit`, but they’re scoped to the `enum` name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these lines should be put here rather than before.
the before splite the explainations of equality operators.

The variants of an `enum` by default are not comparable with equality operators
(`==`, `!=`), have no ordering (`<`, `>=`, etc.), and do not support other
binary operations such as `*` and `+`. As such, the following code is invalid
Expand All @@ -48,16 +58,6 @@ let four_is_smaller = four <= ten;
let four_equals_ten = four == ten;
```

We use the `::` syntax to use the name of each variant: They’re scoped by the name
of the `enum` itself. This allows both of these to work:

```rust,ignore
Character::Digit(10);
Hand::Digit;
```

Both variants are named `Digit`, but since they’re scoped to the `enum` name,

Not supporting these operations may seem rather limiting, but it’s a limitation
which we can overcome. There are two ways: by implementing equality ourselves,
or by pattern matching variants with [`match`][match] expressions, which you’ll
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn takes_anything<T>(x: T) {
```

The syntax has two parts: the `<T>` says “this function is generic over one
type, `T`”, and the `x: T` says “x has the type `T`.”
type, `T`”, and the `x: T` says “x has the type `T`”.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commas go inside of double quotes, actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for that, my english is not very good,maybe I'm wrong.


Multiple arguments can have the same generic type:

Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/if-let.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ loop as long as a value matches a certain pattern. It turns code like this:
loop {
match option {
Some(x) => println!("{}", x),
_ => break,
_ => break,
}
}
```
Expand Down
3 changes: 2 additions & 1 deletion src/doc/trpl/vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ There’s an alternate form of `vec!` for repeating an initial value:
let v = vec![0; 10]; // ten zeroes
```

[generic]: generics.html

## Accessing elements

To get the value at a particular index in the vector, we use `[]`s:
Expand Down Expand Up @@ -56,4 +58,3 @@ Vectors have many more useful methods, which you can read about in [their
API documentation][vec].

[vec]: ../std/vec/index.html
[generic]: generics.html