Skip to content

Commit f94d71a

Browse files
committed
---
yaml --- r: 31445 b: refs/heads/dist-snap c: 8209b2e h: refs/heads/master i: 31443: 013b5db v: v3
1 parent 4c0bf11 commit f94d71a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+577
-881
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 44631722ff234241cb7100103320a402fe4fdfa9
10+
refs/heads/dist-snap: 8209b2e9b383b9e38a09b1ec79c7b5691aeb5d22
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/doc/tutorial.md

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ high-level features include:
3434
* ***Higher-order functions.*** Rust functions may take closures as
3535
arguments or return closures as return values. Closures in Rust are
3636
very powerful and used pervasively.
37-
* ***Trait polymorphism.*** Rust's type system features a unique
38-
combination of Java-style interfaces and Haskell-style typeclasses
39-
called _traits_.
37+
* ***Interface polymorphism.*** Rust's type system features a unique
38+
combination of Java-style interfaces and Haskell-style typeclasses.
4039
* ***Parametric polymorphism (generics).*** Functions and types can be
4140
parameterized over type variables with optional type constraints.
4241
* ***Type inference.*** Type annotations on local variable
@@ -735,12 +734,9 @@ of numeric literal patterns can be expressed with `to`. The underscore
735734
(`_`) is a wildcard pattern that matches everything.
736735

737736
If the arm with the wildcard pattern was left off in the above
738-
example, the typechecker would reject it at compile time. `alt`
739-
constructs must be exhaustive: they must have an arm covering every
740-
possible case. (You may use the `alt check` construct to write a
741-
non-exhaustive match, but it's highly undesirable to do so. You may
742-
reason that the missing cases will never occur, but the typechecker
743-
provides you with no assurance that your reasoning is correct.)
737+
example, running it on a number greater than ten (or negative) would
738+
cause a run-time failure. When no arm matches, `alt` constructs do not
739+
silently fall through—they blow up instead.
744740

745741
A powerful application of pattern matching is *destructuring*, where
746742
you use the matching to get at the contents of data types. Remember
@@ -2093,9 +2089,9 @@ resource type. Rust has several kinds that can be used as type bounds:
20932089
mutable fields nor shared boxes.
20942090

20952091
> ***Note:*** Rust type kinds are syntactically very similar to
2096-
> [traits](#traits) when used as type bounds, and can be
2097-
> conveniently thought of as built-in traits. In the future type
2098-
> kinds will actually be traits that the compiler has special
2092+
> [interfaces](#interfaces) when used as type bounds, and can be
2093+
> conveniently thought of as built-in interfaces. In the future type
2094+
> kinds will actually be interfaces that the compiler has special
20992095
> knowledge about.
21002096
21012097
## Generic functions and argument-passing
@@ -2392,9 +2388,9 @@ This makes it possible to rebind a variable without actually mutating
23922388
it, which is mostly useful for destructuring (which can rebind, but
23932389
not assign).
23942390

2395-
# Traits
2391+
# Interfaces
23962392

2397-
Traits are Rust's take on value polymorphism—the thing that
2393+
Interfaces are Rust's take on value polymorphism—the thing that
23982394
object-oriented languages tend to solve with methods and inheritance.
23992395
For example, writing a function that can operate on multiple types of
24002396
collections.
@@ -2404,27 +2400,27 @@ collections.
24042400
24052401
## Declaration
24062402

2407-
A trait consists of a set of methods. A method is a function that
2403+
An interface consists of a set of methods. A method is a function that
24082404
can be applied to a `self` value and a number of arguments, using the
24092405
dot notation: `self.foo(arg1, arg2)`.
24102406

2411-
For example, we could declare the trait `to_str` for things that
2407+
For example, we could declare the interface `to_str` for things that
24122408
can be converted to a string, with a single method of the same name:
24132409

24142410
~~~~
2415-
trait to_str {
2411+
iface to_str {
24162412
fn to_str() -> ~str;
24172413
}
24182414
~~~~
24192415

24202416
## Implementation
24212417

2422-
To actually implement an trait for a given type, the `impl` form
2418+
To actually implement an interface for a given type, the `impl` form
24232419
is used. This defines implementations of `to_str` for the `int` and
24242420
`~str` types.
24252421

24262422
~~~~
2427-
# trait to_str { fn to_str() -> ~str; }
2423+
# iface to_str { fn to_str() -> ~str; }
24282424
impl of to_str for int {
24292425
fn to_str() -> ~str { int::to_str(self, 10u) }
24302426
}
@@ -2443,13 +2439,13 @@ method that matches the name, and simply calls that.
24432439

24442440
Implementations are not globally visible. Resolving a method to an
24452441
implementation requires that implementation to be in scope. You can
2446-
import and export implementations using the name of the trait they
2442+
import and export implementations using the name of the interface they
24472443
implement (multiple implementations with the same name can be in scope
24482444
without problems). Or you can give them an explicit name if you
24492445
prefer, using this syntax:
24502446

24512447
~~~~
2452-
# trait to_str { fn to_str() -> ~str; }
2448+
# iface to_str { fn to_str() -> ~str; }
24532449
impl nil_to_str of to_str for () {
24542450
fn to_str() -> ~str { ~"()" }
24552451
}
@@ -2465,7 +2461,7 @@ known at compile time, it is possible to specify 'bounds' for type
24652461
parameters.
24662462

24672463
~~~~
2468-
# trait to_str { fn to_str() -> ~str; }
2464+
# iface to_str { fn to_str() -> ~str; }
24692465
fn comma_sep<T: to_str>(elts: ~[T]) -> ~str {
24702466
let mut result = ~"", first = true;
24712467
for elts.each |elt| {
@@ -2480,18 +2476,18 @@ fn comma_sep<T: to_str>(elts: ~[T]) -> ~str {
24802476
The syntax for this is similar to the syntax for specifying that a
24812477
parameter type has to be copyable (which is, in principle, another
24822478
kind of bound). By declaring `T` as conforming to the `to_str`
2483-
trait, it becomes possible to call methods from that trait on
2479+
interface, it becomes possible to call methods from that interface on
24842480
values of that type inside the function. It will also cause a
24852481
compile-time error when anyone tries to call `comma_sep` on an array
24862482
whose element type does not have a `to_str` implementation in scope.
24872483

2488-
## Polymorphic traits
2484+
## Polymorphic interfaces
24892485

2490-
Traits may contain type parameters. This defines a trait for
2486+
Interfaces may contain type parameters. This defines an interface for
24912487
generalized sequence types:
24922488

24932489
~~~~
2494-
trait seq<T> {
2490+
iface seq<T> {
24952491
fn len() -> uint;
24962492
fn iter(fn(T));
24972493
}
@@ -2503,26 +2499,26 @@ impl <T> of seq<T> for ~[T] {
25032499
}
25042500
~~~~
25052501

2506-
Note that the implementation has to explicitly declare the type
2507-
parameter that it binds, `T`, before using it to specify its trait type. This is
2502+
Note that the implementation has to explicitly declare the its
2503+
parameter `T` before using it to specify its interface type. This is
25082504
needed because it could also, for example, specify an implementation
25092505
of `seq<int>`—the `of` clause *refers* to a type, rather than defining
25102506
one.
25112507

2512-
The type parameters bound by a trait are in scope in each of the
2508+
The type parameters bound by an iface are in scope in each of the
25132509
method declarations. So, re-declaring the type parameter
2514-
`T` as an explicit type parameter for `len` -- in either the trait or
2510+
`T` as an explicit type parameter for `len` -- in either the iface or
25152511
the impl -- would be a compile-time error.
25162512

2517-
## The `self` type in traits
2513+
## The `self` type in interfaces
25182514

2519-
In a trait, `self` is a special type that you can think of as a
2520-
type parameter. An implementation of the trait for any given type
2515+
In an interface, `self` is a special type that you can think of as a
2516+
type parameter. An implementation of the interface for any given type
25212517
`T` replaces the `self` type parameter with `T`. The following
2522-
trait describes types that support an equality operation:
2518+
interface describes types that support an equality operation:
25232519

25242520
~~~~
2525-
trait eq {
2521+
iface eq {
25262522
fn equals(&&other: self) -> bool;
25272523
}
25282524
@@ -2534,15 +2530,15 @@ impl of eq for int {
25342530
Notice that `equals` takes an `int` argument, rather than a `self` argument, in
25352531
an implementation for type `int`.
25362532

2537-
## Casting to an trait type
2533+
## Casting to an interface type
25382534

25392535
The above allows us to define functions that polymorphically act on
2540-
values of *an* unknown type that conforms to a given trait.
2536+
values of *an* unknown type that conforms to a given interface.
25412537
However, consider this function:
25422538

25432539
~~~~
25442540
# type circle = int; type rectangle = int;
2545-
# trait drawable { fn draw(); }
2541+
# iface drawable { fn draw(); }
25462542
# impl of drawable for int { fn draw() {} }
25472543
# fn new_circle() -> int { 1 }
25482544
fn draw_all<T: drawable>(shapes: ~[T]) {
@@ -2553,14 +2549,14 @@ fn draw_all<T: drawable>(shapes: ~[T]) {
25532549
~~~~
25542550

25552551
You can call that on an array of circles, or an array of squares
2556-
(assuming those have suitable `drawable` traits defined), but not
2552+
(assuming those have suitable `drawable` interfaces defined), but not
25572553
on an array containing both circles and squares.
25582554

2559-
When this is needed, a trait name can be used as a type, causing
2555+
When this is needed, an interface name can be used as a type, causing
25602556
the function to be written simply like this:
25612557

25622558
~~~~
2563-
# trait drawable { fn draw(); }
2559+
# iface drawable { fn draw(); }
25642560
fn draw_all(shapes: ~[drawable]) {
25652561
for shapes.each |shape| { shape.draw(); }
25662562
}
@@ -2575,11 +2571,11 @@ is very similar to the 'vtables' used in most object-oriented
25752571
languages.
25762572

25772573
To construct such a value, you use the `as` operator to cast a value
2578-
to a trait type:
2574+
to an interface type:
25792575

25802576
~~~~
25812577
# type circle = int; type rectangle = int;
2582-
# trait drawable { fn draw(); }
2578+
# iface drawable { fn draw(); }
25832579
# impl of drawable for int { fn draw() {} }
25842580
# fn new_circle() -> int { 1 }
25852581
# fn new_rectangle() -> int { 2 }
@@ -2598,10 +2594,10 @@ Note that the allocation of a box is somewhat more expensive than
25982594
simply using a type parameter and passing in the value as-is, and much
25992595
more expensive than statically resolved method calls.
26002596

2601-
## Trait-less implementations
2597+
## Interface-less implementations
26022598

26032599
If you only intend to use an implementation for static overloading,
2604-
and there is no trait available that it conforms to, you are free
2600+
and there is no interface available that it conforms to, you are free
26052601
to leave off the `of` clause. However, this is only possible when you
26062602
are defining an implementation in the same module as the receiver
26072603
type, and the receiver type is a named type (i.e., an enum or a
@@ -2624,10 +2620,9 @@ OpenSSL libraries installed, it should 'just work'.
26242620

26252621
~~~~ {.xfail-test}
26262622
use std;
2627-
import libc::c_uint;
26282623
26292624
extern mod crypto {
2630-
fn SHA1(src: *u8, sz: c_uint, out: *u8) -> *u8;
2625+
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
26312626
}
26322627
26332628
fn as_hex(data: ~[u8]) -> ~str {
@@ -2639,7 +2634,7 @@ fn as_hex(data: ~[u8]) -> ~str {
26392634
fn sha1(data: ~str) -> ~str unsafe {
26402635
let bytes = str::bytes(data);
26412636
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
2642-
vec::len(bytes) as c_uint, ptr::null());
2637+
vec::len(bytes), ptr::null());
26432638
ret as_hex(vec::unsafe::from_buf(hash, 20u));
26442639
}
26452640
@@ -2705,7 +2700,7 @@ return a pointer.
27052700

27062701
~~~~ {.xfail-test}
27072702
# extern mod crypto {
2708-
fn SHA1(src: *u8, sz: libc::c_uint, out: *u8) -> *u8;
2703+
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
27092704
# }
27102705
~~~~
27112706

@@ -2796,7 +2791,7 @@ This pointer will become invalid as soon as the vector it points into
27962791
is cleaned up, so you should be very careful how you use it. In this
27972792
case, the local variable `bytes` outlives the pointer, so we're good.
27982793

2799-
Passing a null pointer as the third argument to `SHA1` makes it use a
2794+
Passing a null pointer as third argument to `SHA1` causes it to use a
28002795
static buffer, and thus save us the effort of allocating memory
28012796
ourselves. `ptr::null` is a generic function that will return an
28022797
unsafe null pointer of the correct type (Rust generics are awesome
@@ -2819,17 +2814,15 @@ microsecond-resolution timer.
28192814

28202815
~~~~
28212816
use std;
2822-
import libc::c_ulonglong;
2823-
2824-
type timeval = {mut tv_sec: c_ulonglong,
2825-
mut tv_usec: c_ulonglong};
2817+
type timeval = {mut tv_sec: uint,
2818+
mut tv_usec: uint};
28262819
#[nolink]
2827-
extern mod lib_c {
2820+
extern mod libc {
28282821
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
28292822
}
28302823
fn unix_time_in_microseconds() -> u64 unsafe {
2831-
let x = {mut tv_sec: 0 as c_ulonglong, mut tv_usec: 0 as c_ulonglong};
2832-
lib_c::gettimeofday(ptr::addr_of(x), ptr::null());
2824+
let x = {mut tv_sec: 0u, mut tv_usec: 0u};
2825+
libc::gettimeofday(ptr::addr_of(x), ptr::null());
28332826
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
28342827
}
28352828
@@ -2845,8 +2838,8 @@ define a record type with the same contents, and declare
28452838

28462839
The second argument to `gettimeofday` (the time zone) is not used by
28472840
this program, so it simply declares it to be a pointer to the nil
2848-
type. Since all null pointers have the same representation regardless of
2849-
their referent type, this is safe.
2841+
type. Since null pointer look the same, no matter which type they are
2842+
supposed to point at, this is safe.
28502843

28512844
# Tasks
28522845

branches/dist-snap/mk/tests.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ cleantestlibs:
9595
check: cleantestlibs cleantmptestlogs tidy all check-stage2
9696
$(Q)$(S)src/etc/check-summary.py tmp/*.log
9797

98-
check-notidy: cleantestlibs cleantmptestlogs all check-stage2
99-
$(Q)$(S)src/etc/check-summary.py tmp/*.log
100-
10198
check-full: cleantestlibs cleantmptestlogs tidy \
10299
all check-stage1 check-stage2 check-stage3
103100
$(Q)$(S)src/etc/check-summary.py tmp/*.log

0 commit comments

Comments
 (0)