Replace io::println by println as it is now included in prelude.rs

This commit is contained in:
Olivier Saut 2013-05-10 21:12:11 +02:00
parent fdf601eaf3
commit 017e7e8be1

View File

@ -129,7 +129,7 @@ we have a file `hello.rs` containing this program:
~~~~ ~~~~
fn main() { fn main() {
io::println("hello?"); println("hello?");
} }
~~~~ ~~~~
@ -139,12 +139,12 @@ Windows) which, upon running, will likely do exactly what you expect.
The Rust compiler tries to provide useful information when it encounters an The Rust compiler tries to provide useful information when it encounters an
error. If you introduce an error into the program (for example, by changing error. If you introduce an error into the program (for example, by changing
`io::println` to some nonexistent function), and then compile it, you'll see `println` to some nonexistent function), and then compile it, you'll see
an error message like this: an error message like this:
~~~~ {.notrust} ~~~~ {.notrust}
hello.rs:2:4: 2:16 error: unresolved name: io::print_with_unicorns hello.rs:2:4: 2:16 error: unresolved name: print_with_unicorns
hello.rs:2 io::print_with_unicorns("hello?"); hello.rs:2 print_with_unicorns("hello?");
^~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~
~~~~ ~~~~
@ -227,7 +227,7 @@ let hi = "hi";
let mut count = 0; let mut count = 0;
while count < 10 { while count < 10 {
io::println(fmt!("count: %?", count)); println(fmt!("count: %?", count));
count += 1; count += 1;
} }
~~~~ ~~~~
@ -400,10 +400,10 @@ don't match the types of the arguments.
~~~~ ~~~~
# let mystery_object = (); # let mystery_object = ();
io::println(fmt!("%s is %d", "the answer", 43)); println(fmt!("%s is %d", "the answer", 43));
// %? will conveniently print any type // %? will conveniently print any type
io::println(fmt!("what is this thing: %?", mystery_object)); println(fmt!("what is this thing: %?", mystery_object));
~~~~ ~~~~
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf [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
~~~~ ~~~~
if false { if false {
io::println("that's odd"); println("that's odd");
} else if true { } else if true {
io::println("right"); println("right");
} else { } else {
io::println("neither true nor false"); println("neither true nor false");
} }
~~~~ ~~~~
@ -454,10 +454,10 @@ executes its corresponding arm.
~~~~ ~~~~
# let my_number = 1; # let my_number = 1;
match my_number { match my_number {
0 => io::println("zero"), 0 => println("zero"),
1 | 2 => io::println("one or two"), 1 | 2 => println("one or two"),
3..10 => io::println("three to ten"), 3..10 => println("three to ten"),
_ => io::println("something else") _ => println("something else")
} }
~~~~ ~~~~
@ -483,8 +483,8 @@ commas are optional.
~~~ ~~~
# let my_number = 1; # let my_number = 1;
match my_number { match my_number {
0 => { io::println("zero") } 0 => { println("zero") }
_ => { io::println("something else") } _ => { println("something else") }
} }
~~~ ~~~
@ -560,7 +560,7 @@ let mut x = 5;
loop { loop {
x += x - 3; x += x - 3;
if x % 5 == 0 { break; } if x % 5 == 0 { break; }
io::println(int::to_str(x)); println(int::to_str(x));
} }
~~~~ ~~~~
@ -614,8 +614,8 @@ origin.y += 1.0; // ERROR: assigning to immutable field
# struct Point { x: float, y: float } # struct Point { x: float, y: float }
# let mypoint = Point { x: 0.0, y: 0.0 }; # let mypoint = Point { x: 0.0, y: 0.0 };
match mypoint { match mypoint {
Point { x: 0.0, y: yy } => { io::println(yy.to_str()); } Point { x: 0.0, y: yy } => { println(yy.to_str()); }
Point { x: xx, y: yy } => { io::println(xx.to_str() + " " + yy.to_str()); } Point { x: xx, y: yy } => { println(xx.to_str() + " " + yy.to_str()); }
} }
~~~~ ~~~~
@ -630,7 +630,7 @@ reuses the field name as the binding name.
# struct Point { x: float, y: float } # struct Point { x: float, y: float }
# let mypoint = Point { x: 0.0, y: 0.0 }; # let mypoint = Point { x: 0.0, y: 0.0 };
match mypoint { match mypoint {
Point { x, _ } => { io::println(x.to_str()) } Point { x, _ } => { println(x.to_str()) }
} }
~~~ ~~~
@ -1231,7 +1231,7 @@ something silly like
~~~ ~~~
# struct Point { x: float, y: float } # struct Point { x: float, y: float }
let point = &@~Point { x: 10f, y: 20f }; let point = &@~Point { x: 10f, y: 20f };
io::println(fmt!("%f", point.x)); println(fmt!("%f", point.x));
~~~ ~~~
The indexing operator (`[]`) also auto-dereferences. The indexing operator (`[]`) also auto-dereferences.
@ -1373,7 +1373,6 @@ and [`core::str`]. Here are some examples.
[`core::str`]: core/str.html [`core::str`]: core/str.html
~~~ ~~~
# use core::io::println;
# enum Crayon { # enum Crayon {
# Almond, AntiqueBrass, Apricot, # Almond, AntiqueBrass, Apricot,
# Aquamarine, Asparagus, AtomicTangerine, # Aquamarine, Asparagus, AtomicTangerine,
@ -1428,7 +1427,6 @@ Rust also supports _closures_, functions that can access variables in
the enclosing scope. the enclosing scope.
~~~~ ~~~~
# use println = core::io::println;
fn call_closure_with_ten(b: &fn(int)) { b(10); } fn call_closure_with_ten(b: &fn(int)) { b(10); }
let captured_var = 20; let captured_var = 20;
@ -1490,7 +1488,7 @@ fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
fn main() { fn main() {
let shout = mk_appender(~"!"); let shout = mk_appender(~"!");
io::println(shout(~"hey ho, let's go")); println(shout(~"hey ho, let's go"));
} }
~~~~ ~~~~
@ -1632,7 +1630,6 @@ And using this function to iterate over a vector:
~~~~ ~~~~
# use each = core::vec::each; # use each = core::vec::each;
# use println = core::io::println;
each([2, 4, 8, 5, 16], |n| { each([2, 4, 8, 5, 16], |n| {
if *n % 2 != 0 { if *n % 2 != 0 {
println("found odd number!"); println("found odd number!");
@ -1649,7 +1646,6 @@ to the next iteration, write `loop`.
~~~~ ~~~~
# use each = core::vec::each; # use each = core::vec::each;
# use println = core::io::println;
for each([2, 4, 8, 5, 16]) |n| { for each([2, 4, 8, 5, 16]) |n| {
if *n % 2 != 0 { if *n % 2 != 0 {
println("found odd number!"); println("found odd number!");
@ -1982,7 +1978,7 @@ struct TimeBomb {
impl Drop for TimeBomb { impl Drop for TimeBomb {
fn finalize(&self) { fn finalize(&self) {
for old_iter::repeat(self.explosivity) { for old_iter::repeat(self.explosivity) {
io::println("blam!"); println("blam!");
} }
} }
} }
@ -2014,11 +2010,11 @@ and `~str`.
~~~~ ~~~~
# trait Printable { fn print(&self); } # trait Printable { fn print(&self); }
impl Printable for int { impl Printable for int {
fn print(&self) { io::println(fmt!("%d", *self)) } fn print(&self) { println(fmt!("%d", *self)) }
} }
impl Printable for ~str { impl Printable for ~str {
fn print(&self) { io::println(*self) } fn print(&self) { println(*self) }
} }
# 1.print(); # 1.print();
@ -2307,7 +2303,7 @@ mod farm {
} }
fn main() { fn main() {
io::println(farm::chicken()); println(farm::chicken());
} }
~~~~ ~~~~
@ -2507,7 +2503,7 @@ pub fn explore() -> &str { "world" }
~~~~ {.xfail-test} ~~~~ {.xfail-test}
// main.rs // main.rs
extern mod world; extern mod world;
fn main() { io::println(~"hello " + world::explore()); } fn main() { println(~"hello " + world::explore()); }
~~~~ ~~~~
Now compile and run like this (adjust to your platform if necessary): Now compile and run like this (adjust to your platform if necessary):