mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-03 07:48:41 +08:00
Give structs a bit more motivation
they deserve it
This commit is contained in:
parent
ec3939fb73
commit
f7103f86b3
@ -1,7 +1,12 @@
|
||||
# Structs
|
||||
|
||||
`struct`s give us the ability to package up multiple values and
|
||||
keep them in one related structure.
|
||||
`struct`s, short for "structures", give us the ability to name and package
|
||||
together multiple related values that make up a meaningful group. If you come
|
||||
from an object-oriented language, `struct`s are like an object's data
|
||||
attributes. `structs`, along with `enum`s that we talked about in the last
|
||||
chapter, are the building blocks you can use in Rust to create new types in
|
||||
your program's domain in order to take full advantage of Rust's compile-time
|
||||
type checking.
|
||||
|
||||
Let’s write a program which calculates the distance between two points.
|
||||
We’ll start off with single variable bindings, and then refactor it to
|
||||
|
Loading…
Reference in New Issue
Block a user