@@ -212,7 +212,7 @@ do drop
212
212
else enum extern
213
213
false fn for
214
214
if impl
215
- let log loop
215
+ let loop
216
216
match mod mut
217
217
priv pub pure
218
218
ref return
@@ -805,21 +805,20 @@ Use declarations support a number of "convenience" notations:
805
805
An example of ` use ` declarations:
806
806
807
807
~~~~
808
- use foo = core::info;
809
808
use core::float::sin;
810
809
use core::str::{slice, to_upper};
811
810
use core::option::Some;
812
811
813
812
fn main() {
814
- // Equivalent to 'log(core:: info, core::float::sin(1.0));'
815
- log(foo, sin(1.0));
813
+ // Equivalent to 'info!( core::float::sin(1.0));'
814
+ info!( sin(1.0));
816
815
817
- // Equivalent to 'log(core:: info, core::option::Some(1.0));'
818
- log( info, Some(1.0));
816
+ // Equivalent to 'info!( core::option::Some(1.0));'
817
+ info!( Some(1.0));
819
818
820
- // Equivalent to 'log(core::info,
821
- // core::str::to_upper(core::str::slice("foo", 0, 1)));'
822
- log( info, to_upper(slice("foo", 0, 1)));
819
+ // Equivalent to
820
+ // 'info!( core::str::to_upper(core::str::slice("foo", 0, 1)));'
821
+ info!( to_upper(slice("foo", 0, 1)));
823
822
}
824
823
~~~~
825
824
@@ -889,10 +888,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
889
888
the function name.
890
889
891
890
~~~~ {.xfail-test}
892
- fn iter<T>(seq: &[T], f: fn(T)) {
891
+ fn iter<T>(seq: &[T], f: & fn(T)) {
893
892
for seq.each |elt| { f(elt); }
894
893
}
895
- fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
894
+ fn map<T, U>(seq: &[T], f: & fn(T) -> U) -> ~[U] {
896
895
let mut acc = ~[];
897
896
for seq.each |elt| { acc.push(f(elt)); }
898
897
acc
@@ -990,7 +989,7 @@ output slot type would normally be. For example:
990
989
991
990
~~~~
992
991
fn my_err(s: &str) -> ! {
993
- log( info, s);
992
+ info!( s);
994
993
fail!();
995
994
}
996
995
~~~~
@@ -1182,8 +1181,8 @@ Traits are implemented for specific types through separate [implementations](#im
1182
1181
# type BoundingBox = int;
1183
1182
1184
1183
trait Shape {
1185
- fn draw(Surface);
1186
- fn bounding_box() -> BoundingBox;
1184
+ fn draw(&self, Surface);
1185
+ fn bounding_box(&self ) -> BoundingBox;
1187
1186
}
1188
1187
~~~~
1189
1188
@@ -1196,9 +1195,9 @@ These appear after the trait name, using the same syntax used in [generic functi
1196
1195
1197
1196
~~~~
1198
1197
trait Seq<T> {
1199
- fn len() -> uint;
1200
- fn elt_at(n: uint) -> T;
1201
- fn iter(fn(T));
1198
+ fn len(&self ) -> uint;
1199
+ fn elt_at(&self, n: uint) -> T;
1200
+ fn iter(&self, & fn(T));
1202
1201
}
1203
1202
~~~~
1204
1203
@@ -1210,7 +1209,7 @@ For example:
1210
1209
1211
1210
~~~~
1212
1211
# type Surface = int;
1213
- # trait Shape { fn draw(Surface); }
1212
+ # trait Shape { fn draw(&self, Surface); }
1214
1213
1215
1214
fn draw_twice<T: Shape>(surface: Surface, sh: T) {
1216
1215
sh.draw(surface);
@@ -1228,7 +1227,7 @@ to pointers to the trait name, used as a type.
1228
1227
# impl Shape for int { }
1229
1228
# let mycircle = 0;
1230
1229
1231
- let myshape: Shape = @mycircle as @Shape;
1230
+ let myshape: @ Shape = @mycircle as @Shape;
1232
1231
~~~~
1233
1232
1234
1233
The resulting value is a managed box containing the value that was cast,
@@ -1272,8 +1271,8 @@ methods of the supertrait may be called on values of subtrait-bound type paramet
1272
1271
Refering to the previous example of ` trait Circle : Shape ` :
1273
1272
1274
1273
~~~
1275
- # trait Shape { fn area() -> float; }
1276
- # trait Circle : Shape { fn radius() -> float; }
1274
+ # trait Shape { fn area(&self ) -> float; }
1275
+ # trait Circle : Shape { fn radius(&self ) -> float; }
1277
1276
fn radius_times_area<T: Circle>(c: T) -> float {
1278
1277
// `c` is both a Circle and a Shape
1279
1278
c.radius() * c.area()
@@ -1283,10 +1282,10 @@ fn radius_times_area<T: Circle>(c: T) -> float {
1283
1282
Likewise, supertrait methods may also be called on trait objects.
1284
1283
1285
1284
~~~ {.xfail-test}
1286
- # trait Shape { fn area() -> float; }
1287
- # trait Circle : Shape { fn radius() -> float; }
1288
- # impl Shape for int { fn area() -> float { 0.0 } }
1289
- # impl Circle for int { fn radius() -> float { 0.0 } }
1285
+ # trait Shape { fn area(&self ) -> float; }
1286
+ # trait Circle : Shape { fn radius(&self ) -> float; }
1287
+ # impl Shape for int { fn area(&self ) -> float { 0.0 } }
1288
+ # impl Circle for int { fn radius(&self ) -> float { 0.0 } }
1290
1289
# let mycircle = 0;
1291
1290
1292
1291
let mycircle: Circle = @mycircle as @Circle;
@@ -1303,7 +1302,7 @@ Implementations are defined with the keyword `impl`.
1303
1302
# struct Point {x: float, y: float};
1304
1303
# type Surface = int;
1305
1304
# struct BoundingBox {x: float, y: float, width: float, height: float};
1306
- # trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; }
1305
+ # trait Shape { fn draw(&self, Surface); fn bounding_box(&self ) -> BoundingBox; }
1307
1306
# fn do_draw_circle(s: Surface, c: Circle) { }
1308
1307
1309
1308
struct Circle {
@@ -1312,8 +1311,8 @@ struct Circle {
1312
1311
}
1313
1312
1314
1313
impl Shape for Circle {
1315
- fn draw(s: Surface) { do_draw_circle(s, self); }
1316
- fn bounding_box() -> BoundingBox {
1314
+ fn draw(&self, s: Surface) { do_draw_circle(s, * self); }
1315
+ fn bounding_box(&self ) -> BoundingBox {
1317
1316
let r = self.radius;
1318
1317
BoundingBox{x: self.center.x - r, y: self.center.y - r,
1319
1318
width: 2.0 * r, height: 2.0 * r}
@@ -2074,7 +2073,7 @@ and moving values from the environment into the lambda expression's captured env
2074
2073
An example of a lambda expression:
2075
2074
2076
2075
~~~~
2077
- fn ten_times(f: fn(int)) {
2076
+ fn ten_times(f: & fn(int)) {
2078
2077
let mut i = 0;
2079
2078
while i < 10 {
2080
2079
f(i);
@@ -2177,7 +2176,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug
2177
2176
In this example, both calls to ` f ` are equivalent:
2178
2177
2179
2178
~~~~
2180
- # fn f(f: fn(int)) { }
2179
+ # fn f(f: & fn(int)) { }
2181
2180
# fn g(i: int) { }
2182
2181
2183
2182
f(|j| g(j));
@@ -2397,58 +2396,6 @@ fn max(a: int, b: int) -> int {
2397
2396
}
2398
2397
~~~~
2399
2398
2400
- ### Log expressions
2401
-
2402
- ~~~~~~~~ {.ebnf .gram}
2403
- log_expr : "log" '(' level ',' expr ')' ;
2404
- ~~~~~~~~
2405
-
2406
- Evaluating a ` log ` expression may, depending on runtime configuration, cause a
2407
- value to be appended to an internal diagnostic logging buffer provided by the
2408
- runtime or emitted to a system console. Log expressions are enabled or
2409
- disabled dynamically at run-time on a per-task and per-item basis. See
2410
- [ logging system] ( #logging-system ) .
2411
-
2412
- Each ` log ` expression must be provided with a * level* argument in
2413
- addition to the value to log. The logging level is a ` u32 ` value, where
2414
- lower levels indicate more-urgent levels of logging. By default, the lowest
2415
- four logging levels (` 1_u32 ... 4_u32 ` ) are predefined as the constants
2416
- ` error ` , ` warn ` , ` info ` and ` debug ` in the ` core ` library.
2417
-
2418
- Additionally, the macros ` error! ` , ` warn! ` , ` info! ` and ` debug! ` are defined
2419
- in the default syntax-extension namespace. These expand into calls to the
2420
- logging facility composed with calls to the ` fmt! ` string formatting
2421
- syntax-extension.
2422
-
2423
- The following examples all produce the same output, logged at the ` error `
2424
- logging level:
2425
-
2426
- ~~~~
2427
- # let filename = "bulbasaur";
2428
-
2429
- // Full version, logging a value.
2430
- log(core::error, ~"file not found: " + filename);
2431
-
2432
- // Log-level abbreviated, since core::* is used by default.
2433
- log(error, ~"file not found: " + filename);
2434
-
2435
- // Formatting the message using a format-string and fmt!
2436
- log(error, fmt!("file not found: %s", filename));
2437
-
2438
- // Using the error! macro, that expands to the previous call.
2439
- error!("file not found: %s", filename);
2440
- ~~~~
2441
-
2442
- A ` log ` expression is * not evaluated* when logging at the specified logging-level, module or task is disabled at runtime.
2443
- This makes inactive ` log ` expressions very cheap;
2444
- they should be used extensively in Rust code, as diagnostic aids,
2445
- as they add little overhead beyond a single integer-compare and branch at runtime.
2446
-
2447
- Logging is presently implemented as a language built-in feature,
2448
- as it makes use of compiler-provided, per-module data tables and flags.
2449
- In the future, logging will move into a library, and will no longer be a core expression type.
2450
- It is therefore recommended to use the macro forms of logging (` error! ` , ` debug! ` , etc.) to minimize disruption in code that uses logging.
2451
-
2452
2399
2453
2400
# Type system
2454
2401
@@ -2731,11 +2678,11 @@ An example of an object type:
2731
2678
2732
2679
~~~~~~~~
2733
2680
trait Printable {
2734
- fn to_str() -> ~str;
2681
+ fn to_str(&self ) -> ~str;
2735
2682
}
2736
2683
2737
2684
impl Printable for int {
2738
- fn to_str() -> ~str { int::to_str(self) }
2685
+ fn to_str(&self ) -> ~str { int::to_str(* self) }
2739
2686
}
2740
2687
2741
2688
fn print(a: @Printable) {
@@ -2755,7 +2702,7 @@ and the cast expression in `main`.
2755
2702
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
2756
2703
2757
2704
~~~~~~~
2758
- fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
2705
+ fn map<A: Copy, B: Copy>(f: & fn(A) -> B, xs: &[A]) -> ~[B] {
2759
2706
if xs.len() == 0 { return ~[]; }
2760
2707
let first: B = f(xs[0]);
2761
2708
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
@@ -2774,11 +2721,11 @@ example, in:
2774
2721
2775
2722
~~~~~~~~
2776
2723
trait Printable {
2777
- fn make_string() -> ~str;
2724
+ fn make_string(&self ) -> ~str;
2778
2725
}
2779
2726
2780
2727
impl Printable for ~str {
2781
- fn make_string() -> ~str { copy self }
2728
+ fn make_string(&self ) -> ~str { copy * self }
2782
2729
}
2783
2730
~~~~~~~~
2784
2731
@@ -3149,7 +3096,7 @@ communication facilities.
3149
3096
3150
3097
The runtime contains a system for directing [ logging
3151
3098
expressions] ( #log-expressions ) to a logging console and/or internal logging
3152
- buffers. Logging expressions can be enabled per module.
3099
+ buffers. Logging can be enabled per module.
3153
3100
3154
3101
Logging output is enabled by setting the ` RUST_LOG ` environment
3155
3102
variable. ` RUST_LOG ` accepts a logging specification made up of a
0 commit comments