Skip to content

Commit da47f89

Browse files
committed
---
yaml --- r: 30793 b: refs/heads/incoming c: 2891f5a h: refs/heads/master i: 30791: c4a04d5 v: v3
1 parent d9ae032 commit da47f89

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: e4148932fcab17f6f8bb362df34d7b83e4c57580
9+
refs/heads/incoming: 2891f5abe3c7f455d16930a35bfc8d8d623de0ff
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial-borrowed-ptr.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ a limit duration. Borrowed pointers never claim any kind of ownership
2929
over the data that they point at: instead, they are used for cases
3030
where you like to make use of data for a short time.
3131

32-
As an example, consider a simple record type `point`:
32+
As an example, consider a simple struct type `point`:
3333

3434
~~~
35-
type point = {x: float, y: float};
35+
struct point {x: float, y: float}
3636
~~~
3737

3838
We can use this simple definition to allocate points in many ways. For
@@ -82,7 +82,7 @@ compute_distance(shared_box, unique_box);
8282

8383
Here the `&` operator is used to take the address of the variable
8484
`on_the_stack`; this is because `on_the_stack` has the type `point`
85-
(that is, a record value) and we have to take its address to get a
85+
(that is, a struct value) and we have to take its address to get a
8686
value. We also call this _borrowing_ the local variable
8787
`on_the_stack`, because we are created an alias: that is, another
8888
route to the same data.
@@ -325,15 +325,18 @@ which has been freed.
325325
In fact, the compiler can apply this same kind of reasoning can be
326326
applied to any memory which is _(uniquely) owned by the stack
327327
frame_. So we could modify the previous example to introduce
328-
additional unique pointers and records, and the compiler will still be
328+
additional unique pointers and structs, and the compiler will still be
329329
able to detect possible mutations:
330330

331331
~~~ {.xfail-test}
332332
fn example3() -> int {
333-
let mut x = ~{mut f: ~{g: 3}};
333+
struct R { g: int }
334+
struct S { mut f: ~R }
335+
336+
let mut x = ~S {mut f: ~R {g: 3}};
334337
let y = &x.f.g;
335-
x = ~{mut f: ~{g: 4}}; // Error reported here.
336-
x.f = ~{g: 5}; // Error reported here.
338+
x = ~S {mut f: ~R {g: 4}}; // Error reported here.
339+
x.f = ~R {g: 5}; // Error reported here.
337340
*y
338341
}
339342
~~~
@@ -504,7 +507,7 @@ Stack Memory
504507
~~~
505508

506509
As you can see, the `size` pointer would not be pointing at a `float` and
507-
not a record. This is not good.
510+
not a struct. This is not good.
508511

509512
So, in fact, for every `ref` binding, the compiler will impose the
510513
same rules as the ones we saw for borrowing the interior of a unique
@@ -559,14 +562,14 @@ defined by the caller.
559562

560563
In any case, whatever the lifetime L is, the pointer produced by
561564
`&p.x` always has the same lifetime as `p` itself, as a pointer to a
562-
field of a record is valid as long as the record is valid. Therefore,
565+
field of a struct is valid as long as the struct is valid. Therefore,
563566
the compiler is satisfied with the function `get_x()`.
564567

565568
To drill in this point, let’s look at a variation on the example, this
566569
time one which does not compile:
567570

568571
~~~ {.xfail-test}
569-
type point = {x: float, y: float};
572+
struct point {x: float, y: float}
570573
fn get_x_sh(p: @point) -> &float {
571574
&p.x // Error reported here
572575
}

branches/incoming/doc/tutorial-ffi.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ vector.
205205
## Passing structures
206206

207207
C functions often take pointers to structs as arguments. Since Rust
208-
records are binary-compatible with C structs, Rust programs can call
208+
structs are binary-compatible with C structs, Rust programs can call
209209
such functions directly.
210210

211211
This program uses the POSIX function `gettimeofday` to get a
@@ -215,14 +215,20 @@ microsecond-resolution timer.
215215
extern mod std;
216216
use libc::c_ulonglong;
217217
218-
type timeval = {mut tv_sec: c_ulonglong,
219-
mut tv_usec: c_ulonglong};
218+
struct timeval {
219+
mut tv_sec: c_ulonglong,
220+
mut tv_usec: c_ulonglong
221+
}
222+
220223
#[nolink]
221224
extern mod lib_c {
222225
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
223226
}
224227
fn unix_time_in_microseconds() -> u64 unsafe {
225-
let x = {mut tv_sec: 0 as c_ulonglong, mut tv_usec: 0 as c_ulonglong};
228+
let x = timeval {
229+
mut tv_sec: 0 as c_ulonglong,
230+
mut tv_usec: 0 as c_ulonglong
231+
};
226232
lib_c::gettimeofday(ptr::addr_of(x), ptr::null());
227233
return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
228234
}
@@ -234,8 +240,8 @@ The `#[nolink]` attribute indicates that there's no foreign library to
234240
link in. The standard C library is already linked with Rust programs.
235241

236242
A `timeval`, in C, is a struct with two 32-bit integers. Thus, we
237-
define a record type with the same contents, and declare
238-
`gettimeofday` to take a pointer to such a record.
243+
define a struct type with the same contents, and declare
244+
`gettimeofday` to take a pointer to such a struct.
239245

240246
The second argument to `gettimeofday` (the time zone) is not used by
241247
this program, so it simply declares it to be a pointer to the nil

branches/incoming/doc/tutorial.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,16 +713,16 @@ enum Shape {
713713
}
714714
~~~~
715715

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
719719
includes an identifier of the actual form that it holds, much like the
720720
'tagged union' pattern in C, but with better ergonomics.
721721

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`,
724724
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
726726
create a new circle.
727727

728728
Enum variants need not have type parameters. This, for example, is
@@ -820,7 +820,7 @@ fn point_from_direction(dir: Direction) -> Point {
820820

821821
## Tuples
822822

823-
Tuples in Rust behave exactly like records, except that their fields
823+
Tuples in Rust behave exactly like structs, except that their fields
824824
do not have names (and can thus not be accessed with dot notation).
825825
Tuples can have any arity except for 0 or 1 (though you may consider
826826
nil, `()`, as the empty tuple if you like).
@@ -1006,16 +1006,16 @@ of each is key to using Rust effectively.
10061006

10071007
# Boxes and pointers
10081008

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
10101010
and enums are _not_ represented as pointers to allocated memory in
10111011
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
10141014
copied, not just a pointer.
10151015

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
10191019
the heap, and refer to that through a pointer.
10201020

10211021
Rust supports several types of pointers. The safe pointer types are
@@ -1191,8 +1191,8 @@ compute_distance(shared_box, unique_box);
11911191
~~~
11921192
11931193
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
11961196
value. We also call this _borrowing_ the local variable
11971197
`on_the_stack`, because we are created an alias: that is, another
11981198
route to the same data.
@@ -1517,7 +1517,7 @@ fn each(v: &[int], op: fn(v: &int)) {
15171517
The reason we pass in a *pointer* to an integer rather than the
15181518
integer itself is that this is how the actual `each()` function for
15191519
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
15211521
to copy out of the vector on each iteration. As a caller, if we use a
15221522
closure to provide the final operator argument, we can write it in a
15231523
way that has a pleasant, block-like structure.

0 commit comments

Comments
 (0)