@@ -129,7 +129,7 @@ we have a file `hello.rs` containing this program:
129
129
130
130
~~~~
131
131
fn main() {
132
- io:: println("hello?");
132
+ println("hello?");
133
133
}
134
134
~~~~
135
135
@@ -139,12 +139,12 @@ Windows) which, upon running, will likely do exactly what you expect.
139
139
140
140
The Rust compiler tries to provide useful information when it encounters an
141
141
error. If you introduce an error into the program (for example, by changing
142
- ` io:: println` to some nonexistent function), and then compile it, you'll see
142
+ ` println ` to some nonexistent function), and then compile it, you'll see
143
143
an error message like this:
144
144
145
145
~~~~ {.notrust}
146
- hello.rs:2:4: 2:16 error: unresolved name: io:: print_with_unicorns
147
- hello.rs:2 io:: print_with_unicorns("hello?");
146
+ hello.rs:2:4: 2:16 error: unresolved name: print_with_unicorns
147
+ hello.rs:2 print_with_unicorns("hello?");
148
148
^~~~~~~~~~~~~~~~~~~~~~~
149
149
~~~~
150
150
@@ -227,7 +227,7 @@ let hi = "hi";
227
227
let mut count = 0;
228
228
229
229
while count < 10 {
230
- io:: println(fmt!("count: %?", count));
230
+ println(fmt!("count: %?", count));
231
231
count += 1;
232
232
}
233
233
~~~~
@@ -400,10 +400,10 @@ don't match the types of the arguments.
400
400
~~~~
401
401
# let mystery_object = ();
402
402
403
- io:: println(fmt!("%s is %d", "the answer", 43));
403
+ println(fmt!("%s is %d", "the answer", 43));
404
404
405
405
// %? will conveniently print any type
406
- io:: println(fmt!("what is this thing: %?", mystery_object));
406
+ println(fmt!("what is this thing: %?", mystery_object));
407
407
~~~~
408
408
409
409
[ pf ] : http://en.cppreference.com/w/cpp/io/c/fprintf
@@ -422,11 +422,11 @@ compulsory, an `if` can have an optional `else` clause, and multiple
422
422
423
423
~~~~
424
424
if false {
425
- io:: println("that's odd");
425
+ println("that's odd");
426
426
} else if true {
427
- io:: println("right");
427
+ println("right");
428
428
} else {
429
- io:: println("neither true nor false");
429
+ println("neither true nor false");
430
430
}
431
431
~~~~
432
432
@@ -454,10 +454,10 @@ executes its corresponding arm.
454
454
~~~~
455
455
# let my_number = 1;
456
456
match my_number {
457
- 0 => io:: println("zero"),
458
- 1 | 2 => io:: println("one or two"),
459
- 3..10 => io:: println("three to ten"),
460
- _ => io:: println("something else")
457
+ 0 => println("zero"),
458
+ 1 | 2 => println("one or two"),
459
+ 3..10 => println("three to ten"),
460
+ _ => println("something else")
461
461
}
462
462
~~~~
463
463
@@ -483,8 +483,8 @@ commas are optional.
483
483
~~~
484
484
# let my_number = 1;
485
485
match my_number {
486
- 0 => { io:: println("zero") }
487
- _ => { io:: println("something else") }
486
+ 0 => { println("zero") }
487
+ _ => { println("something else") }
488
488
}
489
489
~~~
490
490
@@ -560,7 +560,7 @@ let mut x = 5;
560
560
loop {
561
561
x += x - 3;
562
562
if x % 5 == 0 { break; }
563
- io:: println(int::to_str(x));
563
+ println(int::to_str(x));
564
564
}
565
565
~~~~
566
566
@@ -614,8 +614,8 @@ origin.y += 1.0; // ERROR: assigning to immutable field
614
614
# struct Point { x: float, y: float }
615
615
# let mypoint = Point { x: 0.0, y: 0.0 };
616
616
match mypoint {
617
- Point { x: 0.0, y: yy } => { io:: println(yy.to_str()); }
618
- Point { x: xx, y: yy } => { io:: println(xx.to_str() + " " + yy.to_str()); }
617
+ Point { x: 0.0, y: yy } => { println(yy.to_str()); }
618
+ Point { x: xx, y: yy } => { println(xx.to_str() + " " + yy.to_str()); }
619
619
}
620
620
~~~~
621
621
@@ -630,7 +630,7 @@ reuses the field name as the binding name.
630
630
# struct Point { x: float, y: float }
631
631
# let mypoint = Point { x: 0.0, y: 0.0 };
632
632
match mypoint {
633
- Point { x, _ } => { io:: println(x.to_str()) }
633
+ Point { x, _ } => { println(x.to_str()) }
634
634
}
635
635
~~~
636
636
@@ -1231,7 +1231,7 @@ something silly like
1231
1231
~~~
1232
1232
# struct Point { x: float, y: float }
1233
1233
let point = &@~ Point { x: 10f, y: 20f };
1234
- io:: println(fmt!("%f", point.x));
1234
+ println(fmt!("%f", point.x));
1235
1235
~~~
1236
1236
1237
1237
The indexing operator (`[]`) also auto-dereferences.
@@ -1373,7 +1373,6 @@ and [`core::str`]. Here are some examples.
1373
1373
[ `core::str` ] : core/str.html
1374
1374
1375
1375
~~~
1376
- # use core::io::println;
1377
1376
# enum Crayon {
1378
1377
# Almond, AntiqueBrass, Apricot,
1379
1378
# Aquamarine, Asparagus, AtomicTangerine,
@@ -1428,7 +1427,6 @@ Rust also supports _closures_, functions that can access variables in
1428
1427
the enclosing scope.
1429
1428
1430
1429
~~~~
1431
- # use println = core::io::println;
1432
1430
fn call_closure_with_ten(b: &fn(int)) { b(10); }
1433
1431
1434
1432
let captured_var = 20;
@@ -1490,7 +1488,7 @@ fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
1490
1488
1491
1489
fn main() {
1492
1490
let shout = mk_appender(~"!");
1493
- io:: println(shout(~"hey ho, let's go"));
1491
+ println(shout(~"hey ho, let's go"));
1494
1492
}
1495
1493
~~~~
1496
1494
@@ -1632,7 +1630,6 @@ And using this function to iterate over a vector:
1632
1630
1633
1631
~~~~
1634
1632
# use each = core::vec::each;
1635
- # use println = core::io::println;
1636
1633
each([2, 4, 8, 5, 16], |n| {
1637
1634
if *n % 2 != 0 {
1638
1635
println("found odd number!");
@@ -1649,7 +1646,6 @@ to the next iteration, write `loop`.
1649
1646
1650
1647
~~~~
1651
1648
# use each = core::vec::each;
1652
- # use println = core::io::println;
1653
1649
for each([2, 4, 8, 5, 16]) |n| {
1654
1650
if *n % 2 != 0 {
1655
1651
println("found odd number!");
@@ -1982,7 +1978,7 @@ struct TimeBomb {
1982
1978
impl Drop for TimeBomb {
1983
1979
fn finalize(&self) {
1984
1980
for old_iter::repeat(self.explosivity) {
1985
- io:: println("blam!");
1981
+ println("blam!");
1986
1982
}
1987
1983
}
1988
1984
}
@@ -2014,11 +2010,11 @@ and `~str`.
2014
2010
~~~~
2015
2011
# trait Printable { fn print(&self); }
2016
2012
impl Printable for int {
2017
- fn print(&self) { io:: println(fmt!("%d", *self)) }
2013
+ fn print(&self) { println(fmt!("%d", *self)) }
2018
2014
}
2019
2015
2020
2016
impl Printable for ~str {
2021
- fn print(&self) { io:: println(*self) }
2017
+ fn print(&self) { println(*self) }
2022
2018
}
2023
2019
2024
2020
# 1.print();
@@ -2307,7 +2303,7 @@ mod farm {
2307
2303
}
2308
2304
2309
2305
fn main() {
2310
- io:: println(farm::chicken());
2306
+ println(farm::chicken());
2311
2307
}
2312
2308
~~~~
2313
2309
@@ -2507,7 +2503,7 @@ pub fn explore() -> &str { "world" }
2507
2503
~~~~ {.xfail-test}
2508
2504
// main.rs
2509
2505
extern mod world;
2510
- fn main() { io:: println(~"hello " + world::explore()); }
2506
+ fn main() { println(~"hello " + world::explore()); }
2511
2507
~~~~
2512
2508
2513
2509
Now compile and run like this (adjust to your platform if necessary):
0 commit comments