@@ -713,16 +713,16 @@ enum Shape {
713
713
}
714
714
~~~~
715
715
716
- A value of this type is either a Circle, in which case it contains a
717
- point struct and a float, or a Rectangle, in which case it contains
718
- two point records . The run-time representation of such a value
716
+ A value of this type is either a ` Circle ` , in which case it contains a
717
+ ` Point ` struct and a float, or a ` Rectangle ` , in which case it contains
718
+ two ` Point ` structs . The run-time representation of such a value
719
719
includes an identifier of the actual form that it holds, much like the
720
720
'tagged union' pattern in C, but with better ergonomics.
721
721
722
- The above declaration will define a type ` shape ` that can be used to
723
- refer to such shapes, and two functions, ` circle ` and ` rectangle ` ,
722
+ The above declaration will define a type ` Shape ` that can be used to
723
+ refer to such shapes, and two functions, ` Circle ` and ` Rectangle ` ,
724
724
which can be used to construct values of the type (taking arguments of
725
- the specified types). So ` circle( {x: 0f, y: 0f}, 10f)` is the way to
725
+ the specified types). So ` Circle(Point {x: 0f, y: 0f}, 10f)` is the way to
726
726
create a new circle.
727
727
728
728
Enum variants need not have type parameters. This, for example, is
@@ -820,7 +820,7 @@ fn point_from_direction(dir: Direction) -> Point {
820
820
821
821
## Tuples
822
822
823
- Tuples in Rust behave exactly like records , except that their fields
823
+ Tuples in Rust behave exactly like structs , except that their fields
824
824
do not have names (and can thus not be accessed with dot notation).
825
825
Tuples can have any arity except for 0 or 1 (though you may consider
826
826
nil, ` () ` , as the empty tuple if you like).
@@ -1006,16 +1006,16 @@ of each is key to using Rust effectively.
1006
1006
1007
1007
# Boxes and pointers
1008
1008
1009
- In contrast to a lot of modern languages, aggregate types like records
1009
+ In contrast to a lot of modern languages, aggregate types like structs
1010
1010
and enums are _ not_ represented as pointers to allocated memory in
1011
1011
Rust. They are, as in C and C++, represented directly. This means that
1012
- if you ` let x = {x: 1f, y: 1f}; ` , you are creating a record on the
1013
- stack. If you then copy it into a data structure, the whole record is
1012
+ if you ` let x = Point {x: 1f, y: 1f}; ` , you are creating a struct on the
1013
+ stack. If you then copy it into a data structure, the whole struct is
1014
1014
copied, not just a pointer.
1015
1015
1016
- For small records like ` point ` , this is usually more efficient than
1017
- allocating memory and going through a pointer. But for big records , or
1018
- records with mutable fields, it can be useful to have a single copy on
1016
+ For small structs like ` Point ` , this is usually more efficient than
1017
+ allocating memory and going through a pointer. But for big structs , or
1018
+ those with mutable fields, it can be useful to have a single copy on
1019
1019
the heap, and refer to that through a pointer.
1020
1020
1021
1021
Rust supports several types of pointers. The safe pointer types are
@@ -1191,8 +1191,8 @@ compute_distance(shared_box, unique_box);
1191
1191
~~~
1192
1192
1193
1193
Here the `&` operator is used to take the address of the variable
1194
- `on_the_stack`; this is because `on_the_stack` has the type `point `
1195
- (that is, a record value) and we have to take its address to get a
1194
+ `on_the_stack`; this is because `on_the_stack` has the type `Point `
1195
+ (that is, a struct value) and we have to take its address to get a
1196
1196
value. We also call this _borrowing_ the local variable
1197
1197
`on_the_stack`, because we are created an alias: that is, another
1198
1198
route to the same data.
@@ -1517,7 +1517,7 @@ fn each(v: &[int], op: fn(v: &int)) {
1517
1517
The reason we pass in a *pointer* to an integer rather than the
1518
1518
integer itself is that this is how the actual `each()` function for
1519
1519
vectors works. Using a pointer means that the function can be used
1520
- for vectors of any type, even large records that would be impractical
1520
+ for vectors of any type, even large structs that would be impractical
1521
1521
to copy out of the vector on each iteration. As a caller, if we use a
1522
1522
closure to provide the final operator argument, we can write it in a
1523
1523
way that has a pleasant, block-like structure.
0 commit comments