Skip to content

Commit 4d41c4b

Browse files
committed
---
yaml --- r: 39933 b: refs/heads/dist-snap c: c4237db h: refs/heads/master i: 39931: 2c0b678 v: v3
1 parent 89a16e9 commit 4d41c4b

File tree

2 files changed

+55
-58
lines changed

2 files changed

+55
-58
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: 06a17a7ce5c2e6ff71fd6d24706dce15f51b8580
10+
refs/heads/dist-snap: c4237db60e35d00257f602a38530aadbc9143689
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/rust.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,12 +1167,12 @@ or constrained by some other [trait type](#trait-types).
11671167
Traits are implemented for specific types through separate [implementations](#implementations).
11681168

11691169
~~~~
1170-
# type surface = int;
1171-
# type bounding_box = int;
1170+
# type Surface = int;
1171+
# type BoundingBox = int;
11721172
1173-
trait shape {
1174-
fn draw(surface);
1175-
fn bounding_box() -> bounding_box;
1173+
trait Shape {
1174+
fn draw(Surface);
1175+
fn bounding_box() -> BoundingBox;
11761176
}
11771177
~~~~
11781178

@@ -1181,101 +1181,98 @@ All values that have [implementations](#implementations) of this trait in scope
11811181
using `value.bounding_box()` [syntax](#method-call-expressions).
11821182

11831183
Type parameters can be specified for a trait to make it generic.
1184-
These appear after the name, using the same syntax used in [generic
1185-
functions](#generic-functions).
1184+
These appear after the trait name, using the same syntax used in [generic functions](#generic-functions).
11861185

11871186
~~~~
1188-
trait seq<T> {
1187+
trait Seq<T> {
11891188
fn len() -> uint;
11901189
fn elt_at(n: uint) -> T;
11911190
fn iter(fn(T));
11921191
}
11931192
~~~~
11941193

1195-
Generic functions may use traits as bounds on their type
1196-
parameters. This will have two effects: only types that have the trait
1197-
may instantiate the parameter, and within the
1198-
generic function, the methods of the trait can be called on values
1199-
that have the parameter's type. For example:
1194+
Generic functions may use traits as _bounds_ on their type parameters.
1195+
This will have two effects: only types that have the trait may instantiate the parameter,
1196+
and within the generic function,
1197+
the methods of the trait can be called on values that have the parameter's type.
1198+
For example:
12001199

12011200
~~~~
1202-
# type surface = int;
1203-
# trait shape { fn draw(surface); }
1201+
# type Surface = int;
1202+
# trait Shape { fn draw(Surface); }
12041203
1205-
fn draw_twice<T: shape>(surface: surface, sh: T) {
1204+
fn draw_twice<T: Shape>(surface: Surface, sh: T) {
12061205
sh.draw(surface);
12071206
sh.draw(surface);
12081207
}
12091208
~~~~
12101209

1211-
Trait items also define a type with the same name as the
1212-
trait. Values of this type are created by
1213-
[casting](#type-cast-expressions) values (of a type for which an
1214-
implementation of the given trait is in scope) to the trait
1215-
type.
1210+
Traits also define a [type](#trait-types) with the same name as the trait.
1211+
Values of this type are created by [casting](#type-cast-expressions) pointer values
1212+
(pointing to a type for which an implementation of the given trait is in scope)
1213+
to pointers to the trait name, used as a type.
12161214

12171215
~~~~
1218-
# trait shape { }
1219-
# impl int: shape { }
1216+
# trait Shape { }
1217+
# impl int: Shape { }
12201218
# let mycircle = 0;
12211219
1222-
let myshape: shape = mycircle as shape;
1220+
let myshape: Shape = @mycircle as @Shape;
12231221
~~~~
12241222

1225-
The resulting value is a reference-counted box containing the value
1226-
that was cast along with information that identify the methods of the
1227-
implementation that was used. Values with a trait type can always
1228-
have methods from their trait called on them, and can be used to
1229-
instantiate type parameters that are bounded by their trait.
1223+
The resulting value is a managed box containing the value that was cast,
1224+
along with information that identify the methods of the implementation that was used.
1225+
Values with a trait type can have [methods called](#method-call-expressions) on them,
1226+
for any method in the trait,
1227+
and can be used to instantiate type parameters that are bounded by the trait.
12301228

12311229
### Implementations
12321230

1233-
An _implementation item_ provides an implementation of a
1234-
[trait](#traits) for a type.
1231+
An _implementation_ is an item that implements a [trait](#traits) for a specific type.
1232+
1233+
Implementations are defined with the keyword `impl`.
12351234

12361235
~~~~
1237-
# type point = {x: float, y: float};
1238-
# type surface = int;
1239-
# type bounding_box = {x: float, y: float, width: float, height: float};
1240-
# trait shape { fn draw(surface); fn bounding_box() -> bounding_box; }
1241-
# fn do_draw_circle(s: surface, c: circle) { }
1236+
# type Point = {x: float, y: float};
1237+
# type Surface = int;
1238+
# type BoundingBox = {x: float, y: float, width: float, height: float};
1239+
# trait Shape { fn draw(surface); fn bounding_box() -> BoundingBox; }
1240+
# fn do_draw_circle(s: Surface, c: Circle) { }
12421241
1243-
type circle = {radius: float, center: point};
1242+
type Circle = {radius: float, center: point};
12441243
1245-
impl circle: shape {
1246-
fn draw(s: surface) { do_draw_circle(s, self); }
1247-
fn bounding_box() -> bounding_box {
1244+
impl Circle: Shape {
1245+
fn draw(s: Surface) { do_draw_circle(s, self); }
1246+
fn bounding_box() -> BoundingBox {
12481247
let r = self.radius;
12491248
{x: self.center.x - r, y: self.center.y - r,
12501249
width: 2.0 * r, height: 2.0 * r}
12511250
}
12521251
}
12531252
~~~~
12541253

1255-
It is possible to define an implementation without referring to a
1256-
trait. The methods in such an implementation can only be used
1257-
statically (as direct calls on the values of the type that the
1258-
implementation targets). In such an implementation, the type after the colon is omitted,
1259-
and the name is mandatory. Such implementations are
1260-
limited to nominal types (enums, structs) and the implementation must
1261-
appear in the same module or a sub-module as the receiver type.
1254+
It is possible to define an implementation without referring to a trait.
1255+
The methods in such an implementation can only be used statically
1256+
(as direct calls on the values of the type that the implementation targets).
1257+
In such an implementation, the type after the colon is omitted.
1258+
Such implementations are limited to nominal types (enums, structs),
1259+
and the implementation must appear in the same module or a sub-module as the `self` type.
12621260

1263-
_When_ a trait is specified, all methods declared as part of the
1264-
trait must be present, with matching types and type parameter
1265-
counts, in the implementation.
1261+
When a trait _is_ specified in an `impl`,
1262+
all methods declared as part of the trait must be implemented,
1263+
with matching types and type parameter counts.
12661264

1267-
An implementation can take type parameters, which can be different
1268-
from the type parameters taken by the trait it implements. They
1269-
are written after the name of the implementation, or if that is not
1270-
specified, after the `impl` keyword.
1265+
An implementation can take type parameters,
1266+
which can be different from the type parameters taken by the trait it implements.
1267+
Implementation parameters are written after after the `impl` keyword.
12711268

12721269
~~~~
1273-
# trait seq<T> { }
1270+
# trait Seq<T> { }
12741271
1275-
impl<T> ~[T]: seq<T> {
1272+
impl<T> ~[T]: Seq<T> {
12761273
...
12771274
}
1278-
impl u32: seq<bool> {
1275+
impl u32: Seq<bool> {
12791276
/* Treat the integer as a sequence of bits */
12801277
}
12811278
~~~~

0 commit comments

Comments
 (0)