Skip to content

Commit 6828587

Browse files
committed
---
yaml --- r: 44859 b: refs/heads/master c: 382143a h: refs/heads/master i: 44857: e759126 44855: 6c218e2 v: v3
1 parent 2fd41d1 commit 6828587

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 332c0460290ade81edf44b55d47edcb4990a3b5a
2+
refs/heads/master: 382143abd871d9b2c73df08ffd2928c44f314ab3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/doc/rust.md

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
908908
with `int`, and require the closure parameter to have type
909909
`fn(int)`.
910910

911+
The type parameters can also be explicitly supplied in a trailing
912+
[path](#paths) component after the function name. This might be necessary
913+
if there is not sufficient context to determine the type parameters. For
914+
example, `sys::size_of::<u32>() == 4`.
915+
911916
Since a parameter type is opaque to the generic function, the set of
912917
operations that can be performed on it is limited. Values of parameter
913918
type can always be moved, but they can only be copied when the
@@ -1085,15 +1090,6 @@ let p = Point(10, 11);
10851090
let px: int = match p { Point(x, _) => x };
10861091
~~~~
10871092

1088-
A _unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
1089-
Such types will have a single value, just like the [unit value `()`](#unit-and-boolean-literals) of the unit type.
1090-
For example:
1091-
1092-
~~~~
1093-
struct Cookie;
1094-
let c = [Cookie, Cookie, Cookie, Cookie];
1095-
~~~~
1096-
10971093
### Enumerations
10981094

10991095
An _enumeration_ is a simultaneous definition of a nominal [enumerated type](#enumerated-types) as well as a set of *constructors*,
@@ -1599,8 +1595,7 @@ struct_expr : expr_path '{' ident ':' expr
15991595
[ ',' ident ':' expr ] *
16001596
[ ".." expr ] '}' |
16011597
expr_path '(' expr
1602-
[ ',' expr ] * ')' |
1603-
expr_path
1598+
[ ',' expr ] * ')'
16041599
~~~~~~~~
16051600

16061601
There are several forms of structure expressions.
@@ -1610,28 +1605,23 @@ providing the field values of a new instance of the structure.
16101605
A field name can be any identifier, and is separated from its value expression by a colon.
16111606
To indicate that a field is mutable, the `mut` keyword is written before its name.
16121607

1613-
A _tuple structure expression_ consists of the [path](#paths) of a [structure item](#structures),
1608+
A _tuple structure expression_ constists of the [path](#paths) of a [structure item](#structures),
16141609
followed by a parenthesized list of one or more comma-separated expressions
16151610
(in other words, the path of a structured item followed by a tuple expression).
16161611
The structure item must be a tuple structure item.
16171612

1618-
A _unit-like structure expression_ consists only of the [path](#paths) of a [structure item](#structures).
1619-
16201613
The following are examples of structure expressions:
16211614

16221615
~~~~
16231616
# struct Point { x: float, y: float }
16241617
# struct TuplePoint(float, float);
16251618
# mod game { pub struct User { name: &str, age: uint, score: uint } }
1626-
# struct Cookie; fn some_fn<T>(t: T) {}
16271619
Point {x: 10f, y: 20f};
16281620
TuplePoint(10f, 20f);
16291621
let u = game::User {name: "Joe", age: 35u, score: 100_000};
1630-
some_fn::<Cookie>(Cookie);
16311622
~~~~
16321623

16331624
A structure expression forms a new value of the named structure type.
1634-
Note that for a given *unit-like* structure type, this will always be the same value.
16351625

16361626
A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
16371627
The expression following `..` (the base) must be of the same structure type as the new structure type being formed.
@@ -2055,12 +2045,14 @@ an optional reference slot to serve as the function's output, bound to the
20552045
`lval` on the right hand side of the call. If the function eventually returns,
20562046
then the expression completes.
20572047

2058-
An example of a call expression:
2048+
Some examples of call expressions:
20592049

20602050
~~~~
20612051
# fn add(x: int, y: int) -> int { 0 }
2052+
# use core::from_str::FromStr::from_str;
20622053
20632054
let x: int = add(1, 2);
2055+
let pi = from_str::<f32>("3.14");
20642056
~~~~
20652057

20662058
### Lambda expressions
@@ -2658,10 +2650,7 @@ the resulting `struct` value will always be laid out in memory in the order spec
26582650
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
26592651
to restrict access to implementation-private data in a structure.
26602652

2661-
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.
2662-
2663-
A _unit-like struct_ type is like a structure type, except that it has no fields.
2664-
The one value constructed by the associated [structure expression](#structure-expression) is the only value that inhabits such a type.
2653+
A `tuple struct` type is just like a structure type, except that the fields are anonymous.
26652654

26662655
### Enumerated types
26672656

0 commit comments

Comments
 (0)