@@ -1195,8 +1195,19 @@ Values with a trait type can have [methods called](#method-call-expressions) on
11951195for any method in the trait,
11961196and can be used to instantiate type parameters that are bounded by the trait.
11971197
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 ` .
12001211
12011212### Implementations
12021213
@@ -1520,8 +1531,11 @@ To indicate that a field is mutable, the `mut` keyword is written before its nam
15201531The following are examples of structure expressions:
15211532
15221533~~~~
1534+ # struct Point { x: float, y: float }
1535+ # mod game { pub struct User { name: &str, age: uint, mut score: uint } }
1536+ # use game;
15231537Point {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};
15251539~~~~
15261540
15271541A 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
15321546and the values in the base record for all other fields.
15331547
15341548~~~~
1549+ # struct Point3d { x: int, y: int, z: int }
15351550let base = Point3d {x: 1, y: 2, z: 3};
15361551Point3d {y: 0, z: 10, .. base};
15371552~~~~
0 commit comments