Skip to content

Commit 133b3d0

Browse files
committed
Update syntax for function arguments; tweak object system examples to
make mutable fields work.
1 parent 5d0f9d9 commit 133b3d0

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

Diff for: doc/rust.texi

+30-30
Original file line numberDiff line numberDiff line change
@@ -1305,14 +1305,14 @@ An example function that accepts an alias parameter:
13051305
@example
13061306
type point3d = @{x: int, y: int, z: int@};
13071307
1308-
fn extract_z(&point3d p) -> int @{
1308+
fn extract_z(p: &point3d) -> int @{
13091309
ret p.z;
13101310
@}
13111311
@end example
13121312

13131313
An example function that accepts an alias to a mutable value:
13141314
@example
1315-
fn incr(& mutable int i) @{
1315+
fn incr(i: &mutable int) @{
13161316
i = i + 1;
13171317
@}
13181318
@end example
@@ -1360,10 +1360,10 @@ indicated with the unary @emph{star} operator @code{*}. Examples of such
13601360

13611361
An example of an explicit-dereference operation performed on box values:
13621362
@example
1363-
fn takes_boxed(@@int b) @{
1363+
fn takes_boxed(b: @@int) @{
13641364
@}
13651365
1366-
fn takes_unboxed(int b) @{
1366+
fn takes_unboxed(b: int) @{
13671367
@}
13681368
13691369
fn main() @{
@@ -1716,7 +1716,7 @@ mod foo @{
17161716
helper(3, 4);
17171717
@}
17181718
1719-
fn helper(int x, int y) @{
1719+
fn helper(x: int, y: int) @{
17201720
@dots{}
17211721
@}
17221722
@}
@@ -1754,15 +1754,15 @@ during compilation, returning the implicit @code{()} value.
17541754

17551755
An example of a function:
17561756
@example
1757-
fn add(int x, int y) -> int @{
1757+
fn add(x: int, y: int) -> int @{
17581758
ret x + y;
17591759
@}
17601760
@end example
17611761

17621762
A special kind of function can be declared with a @code{!} character where the
17631763
output slot type would normally be. For example:
17641764
@example
1765-
fn my_err(str s) -> ! @{
1765+
fn my_err(s: str) -> ! @{
17661766
log s;
17671767
fail;
17681768
@}
@@ -1781,7 +1781,7 @@ with a @code{ret}, @code{be}, or diverging expression. So, if @code{my_err}
17811781
were declared without the @code{!} annotation, the following code would not
17821782
typecheck:
17831783
@example
1784-
fn f(int i) -> int @{
1784+
fn f(i: int) -> int @{
17851785
if (i == 42) @{
17861786
ret 42;
17871787
@}
@@ -1849,7 +1849,7 @@ each} loop or as the argument in a @code{put each} expression.
18491849

18501850
An example of an iterator:
18511851
@example
1852-
iter range(int lo, int hi) -> int @{
1852+
iter range(lo: int, hi: int) -> int @{
18531853
let i: int = lo;
18541854
while (i < hi) @{
18551855
put i;
@@ -1881,16 +1881,16 @@ constructor function when used in value context (such as a call).
18811881

18821882
Example of an object item:
18831883
@example
1884-
obj counter(int state) @{
1884+
obj counter(state: @@mutable int) @{
18851885
fn incr() @{
1886-
state += 1;
1886+
*state += 1;
18871887
@}
18881888
fn get() -> int @{
1889-
ret state;
1889+
ret *state;
18901890
@}
18911891
@}
18921892
1893-
let c: counter = counter(1);
1893+
let c: counter = counter(@@mutable 1);
18941894
18951895
c.incr();
18961896
c.incr();
@@ -2287,7 +2287,7 @@ slot. @xref{Ref.Item.Fn}.
22872287

22882288
An example of a @code{fn} type:
22892289
@example
2290-
fn add(int x, int y) -> int @{
2290+
fn add(x: int, y: int) -> int @{
22912291
ret x + y;
22922292
@}
22932293
@@ -2308,7 +2308,7 @@ constraints and an output slot. @xref{Ref.Item.Iter}.
23082308

23092309
An example of an @code{iter} type:
23102310
@example
2311-
iter range(int x, int y) -> int @{
2311+
iter range(x: int, y: int) -> int @{
23122312
while (x < y) @{
23132313
put x;
23142314
x += 1;
@@ -2433,31 +2433,31 @@ a client function using both items via the object type:
24332433
@example
24342434
24352435
type taker =
2436-
state obj @{
2436+
obj @{
24372437
fn take(int);
24382438
@};
24392439
2440-
obj adder(mutable int x) @{
2441-
fn take(int y) @{
2442-
x += y;
2440+
obj adder(x: @@mutable int) @{
2441+
fn take(y: int) @{
2442+
*x += y;
24432443
@}
24442444
@}
24452445
2446-
obj sender(chan[int] c) @{
2447-
fn take(int z) @{
2446+
obj sender(c: chan[int]) @{
2447+
fn take(z: int) @{
24482448
c <| z;
24492449
@}
24502450
@}
24512451
2452-
fn give_ints(taker t) @{
2452+
fn give_ints(t: taker) @{
24532453
t.take(1);
24542454
t.take(2);
24552455
t.take(3);
24562456
@}
24572457
24582458
let p: port[int] = port();
24592459
2460-
let t1: taker = adder(0);
2460+
let t1: taker = adder(@@mutable 0);
24612461
let t2: taker = sender(chan(p));
24622462
24632463
give_ints(t1);
@@ -2939,7 +2939,7 @@ The result of a @code{spawn} expression is a @code{task} value.
29392939

29402940
An example of a @code{spawn} expression:
29412941
@example
2942-
fn helper(chan[u8] out) @{
2942+
fn helper(out: chan[u8]) @{
29432943
// do some work.
29442944
out <| result;
29452945
@}
@@ -3033,7 +3033,7 @@ and residual arguments that was specified during the binding.
30333033

30343034
An example of a @code{bind} expression:
30353035
@example
3036-
fn add(int x, int y) -> int @{
3036+
fn add(x: int, y: int) -> int @{
30373037
ret x + y;
30383038
@}
30393039
type single_param_fn = fn(int) -> int;
@@ -3070,7 +3070,7 @@ and transfers control to the caller frame.
30703070

30713071
An example of a @code{ret} expression:
30723072
@example
3073-
fn max(int a, int b) -> int @{
3073+
fn max(a: int, b: int) -> int @{
30743074
if (a > b) @{
30753075
ret a;
30763076
@}
@@ -3094,7 +3094,7 @@ last expression in a block.
30943094

30953095
An example of a @code{be} expression:
30963096
@example
3097-
fn print_loop(int n) @{
3097+
fn print_loop(n: int) @{
30983098
if (n <= 0) @{
30993099
ret;
31003100
@} else @{
@@ -3182,7 +3182,7 @@ diagnostic buffer.
31823182

31833183
An example of a @code{note} expression:
31843184
@example
3185-
fn read_file_lines(&str path) -> vec[str] @{
3185+
fn read_file_lines(path: &str) -> vec[str] @{
31863186
note path;
31873187
let r: vec[str];
31883188
let f: file = open_read(path);
@@ -3514,11 +3514,11 @@ and statically comparing implied states and their
35143514
specifications. @xref{Ref.Typestate}.
35153515

35163516
@example
3517-
pred even(&int x) -> bool @{
3517+
pred even(x: &int) -> bool @{
35183518
ret x & 1 == 0;
35193519
@}
35203520
3521-
fn print_even(int x) : even(x) @{
3521+
fn print_even(x: int) : even(x) @{
35223522
print(x);
35233523
@}
35243524

0 commit comments

Comments
 (0)