mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-26 17:28:42 +08:00
Cut discussion of unit structs
es-o-ter-ic 👏👏, 👏👏👏
This commit is contained in:
parent
cf3e963e3f
commit
afbbb0de4a
@ -158,17 +158,10 @@ struct NAME {
|
|||||||
```
|
```
|
||||||
|
|
||||||
The `NAME: TYPE` bit is called a ‘field’, and we can have as many or as few of
|
The `NAME: TYPE` bit is called a ‘field’, and we can have as many or as few of
|
||||||
them as you’d like. If you have none of them, drop the `{}`s:
|
them as we’d like.
|
||||||
|
|
||||||
```rust
|
We can access the field of a struct in the same way we access an element of
|
||||||
struct Foo;
|
a tuple, except we use its name:
|
||||||
```
|
|
||||||
|
|
||||||
`struct`s with no fields are called ‘unit structs’, and are used in certain
|
|
||||||
advanced situations. We will just ignore them for now.
|
|
||||||
|
|
||||||
You can access the field of a struct in the same way you access an element of
|
|
||||||
a tuple, except you use its name:
|
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
let p1 = (0.0, 5.0);
|
let p1 = (0.0, 5.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user