Skip to content

Commit a893d2e

Browse files
1 parent 52f7a4a commit a893d2e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/doc/guide.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,9 @@ time. Here's an example:
10911091

10921092
```{rust}
10931093
fn cmp(a: int, b: int) -> Ordering {
1094-
if a < b { Less }
1095-
else if a > b { Greater }
1096-
else { Equal }
1094+
if a < b { Ordering::Less }
1095+
else if a > b { Ordering::Greater }
1096+
else { Ordering::Equal }
10971097
}
10981098
10991099
fn main() {
@@ -1104,16 +1104,16 @@ fn main() {
11041104
11051105
if ordering == Less {
11061106
println!("less");
1107-
} else if ordering == Greater {
1107+
} else if ordering == Ordering::Greater {
11081108
println!("greater");
1109-
} else if ordering == Equal {
1109+
} else if ordering == Ordering::Equal {
11101110
println!("equal");
11111111
}
11121112
}
11131113
```
11141114

11151115
`cmp` is a function that compares two things, and returns an `Ordering`. We
1116-
return either `Less`, `Greater`, or `Equal`, depending on if the two values
1116+
return either `Ordering::Less`, `Ordering::Greater`, or `Ordring::Equal`, depending on if the two values
11171117
are greater, less, or equal.
11181118

11191119
The `ordering` variable has the type `Ordering`, and so contains one of the
@@ -1160,8 +1160,7 @@ Where a `StringResult` is either an `StringOK`, with the result of a computation
11601160
`ErrorReason` with a `String` explaining what caused the computation to fail. These kinds of
11611161
`enum`s are actually very useful and are even part of the standard library.
11621162

1163-
Enum variants are namespaced under the enum names. For example, here is an example of using
1164-
our `StringResult`:
1163+
Enum variants are namespaced under the enum names. Lets look at another example using our `StringResult` enum:
11651164

11661165
```rust
11671166
# enum StringResult {
@@ -1177,10 +1176,7 @@ fn respond(greeting: &str) -> StringResult {
11771176
}
11781177
```
11791178

1180-
Notice that we need both the enum name and the variant name: `StringResult::StringOK`, but
1181-
we didn't need to with `Ordering`, we just said `Greater` rather than `Ordering::Greater`.
1182-
There's a reason: the Rust prelude imports the variants of `Ordering` as well as the enum
1183-
itself. We can use the `use` keyword to do something similar with `StringResult`:
1179+
Notice that we need both the enum name and the variant name: `StringResult::StringOK`, but we can use the `use` keyword to prevent having to call `StringResult::StringOK` every time we want to use the `StringOK` variant:
11841180

11851181
```rust
11861182
use StringResult::StringOK;

0 commit comments

Comments
 (0)