@@ -1195,8 +1195,19 @@ Values with a trait type can have [methods called](#method-call-expressions) on
1195
1195
for any method in the trait,
1196
1196
and can be used to instantiate type parameters that are bounded by the trait.
1197
1197
1198
- Trait methods may be static. Currently implementations of static methods behave like
1199
- functions declared in the implentation's module.
1198
+ Trait methods may be static.
1199
+ Currently, implementations of static methods behave like functions declared in the implementation's module.
1200
+
1201
+ Traits can have _ constraints_ for example, in
1202
+
1203
+ ~~~~
1204
+ trait Shape { fn area() -> float; }
1205
+ trait Circle : Shape { fn radius() -> float; }
1206
+ ~~~~
1207
+
1208
+ the syntax ` Circle : Shape ` means that types that implement ` Circle ` must also have an implementation for ` Shape ` .
1209
+ In an implementation of ` Circle ` for a given type ` T ` , methods can refer to ` Shape ` methods,
1210
+ since the typechecker checks that any type with an implementation of ` Circle ` also has an implementation of ` Shape ` .
1200
1211
1201
1212
### Implementations
1202
1213
@@ -1520,8 +1531,11 @@ To indicate that a field is mutable, the `mut` keyword is written before its nam
1520
1531
The following are examples of structure expressions:
1521
1532
1522
1533
~~~~
1534
+ # struct Point { x: float, y: float }
1535
+ # mod game { pub struct User { name: &str, age: uint, mut score: uint } }
1536
+ # use game;
1523
1537
Point {x: 10f, y: 20f};
1524
- game::User {name: "Joe", age: 35u, mut score: 100_000};
1538
+ let u = game::User {name: "Joe", age: 35u, mut score: 100_000};
1525
1539
~~~~
1526
1540
1527
1541
A structure expression forms a new value of the named structure type.
@@ -1532,6 +1546,7 @@ A new structure will be created, of the same type as the base expression, with t
1532
1546
and the values in the base record for all other fields.
1533
1547
1534
1548
~~~~
1549
+ # struct Point3d { x: int, y: int, z: int }
1535
1550
let base = Point3d {x: 1, y: 2, z: 3};
1536
1551
Point3d {y: 0, z: 10, .. base};
1537
1552
~~~~
0 commit comments