Skip to content

Commit bbd24e2

Browse files
committed
translate P.NAM.01.md
1 parent d9c42c0 commit bbd24e2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
11
# P.NAM.01 The naming convention for identifiers in the same crate should use a uniform word order
2+
3+
**[Description]**
4+
5+
The particular choice of word order is not important, but pay attention to consistency within the crate and consistency with similar functionality in the standard library.
6+
7+
> For example:
8+
>
9+
> If the naming of types in crate were in **verb-object-error** word order, we need to follow the same order when we adding new types.
10+
11+
Here are some error types from the standard library:
12+
13+
- [`JoinPathsError`](https://doc.rust-lang.org/std/env/struct.JoinPathsError.html)
14+
- [`ParseBoolError`](https://doc.rust-lang.org/std/str/struct.ParseBoolError.html)
15+
- [`ParseCharError`](https://doc.rust-lang.org/std/char/struct.ParseCharError.html)
16+
- [`ParseFloatError`](https://doc.rust-lang.org/std/num/struct.ParseFloatError.html)
17+
- [`ParseIntError`](https://doc.rust-lang.org/std/num/struct.ParseIntError.html)
18+
- [`RecvTimeoutError`](https://doc.rust-lang.org/std/sync/mpsc/enum.RecvTimeoutError.html)
19+
- [`StripPrefixError`](https://doc.rust-lang.org/std/path/struct.StripPrefixError.html)
20+
21+
All of these use verb-object-error word order. If we were adding an error to represent an address failing to parse, for consistency we would want to name it in verb-object-error order like `ParseAddrError` rather than `AddrParseError`.
22+
23+
> Note: The `AddrParseError` of module `net` in the standard library is an exception. Most of the error types from the standard library follow the verb-object-error word order.
24+
25+
**[Bad Case]**
26+
27+
```rust
28+
// Bad:Not the "verb-object-error" order, should be `ParseAddrError`
29+
struct AddrParseError {}
30+
```
31+
32+
**[Good Case]**
33+
34+
```rust
35+
// Good: The order is the same as the standard library
36+
struct ParseAddrError{}
37+
```
38+

0 commit comments

Comments
 (0)