mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
Hard wrap at 80 chars
This commit is contained in:
parent
8f62f51e74
commit
e5a638b4c7
@ -16,10 +16,10 @@ enum IpAddrKind {
|
||||
```
|
||||
|
||||
This enum represents the kind of an IP address. There are two major standards
|
||||
used for IP addresses: version four and version six. Any IP address can be either
|
||||
a version four address or a version six address, but it cannot be both kinds at
|
||||
the same time. This is where enums get their name: they allow us to enumerate all
|
||||
of the possible kinds that our value can have.
|
||||
used for IP addresses: version four and version six. Any IP address can be
|
||||
either a version four address or a version six address, but it cannot be both
|
||||
kinds at the same time. This is where enums get their name: they allow us to
|
||||
enumerate all of the possible kinds that our value can have.
|
||||
|
||||
We can create values of `IpAddrKind` like this:
|
||||
|
||||
@ -97,8 +97,8 @@ let loopback = IpAddr::V6(String::from("::1"));
|
||||
```
|
||||
|
||||
You can put any kind of data inside of an enum variant, including another enum!
|
||||
The `IpAddr` enum is [in the standard library][IpAddr], but it embeds two different
|
||||
structs inside of its variants:
|
||||
The `IpAddr` enum is [in the standard library][IpAddr], but it embeds two
|
||||
different structs inside of its variants:
|
||||
|
||||
```rust
|
||||
struct Ipv4Addr {
|
||||
|
@ -102,8 +102,8 @@ fn plus_one(x: Option<i32>) -> Option<i32> {
|
||||
}
|
||||
```
|
||||
|
||||
A bug! We didn't handle the `None` case. Luckily, it's a bug Rust knows how to catch.
|
||||
If we try to compile this code, we'll get an error:
|
||||
A bug! We didn't handle the `None` case. Luckily, it's a bug Rust knows how to
|
||||
catch. If we try to compile this code, we'll get an error:
|
||||
|
||||
```text
|
||||
error: non-exhaustive patterns: `None` not covered [E0004]
|
||||
|
Loading…
Reference in New Issue
Block a user