Skip to content

Commit 54bb147

Browse files
committed
Release of Rust-0.12.0
1 parent f08a0d6 commit 54bb147

12 files changed

+57
-81
lines changed

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
# Use something that's not 'ruby' so we don't set up things like
2-
# RVM/bundler/ruby and whatnot. Right now 'rust' isn't a language on
3-
# travis and it treats unknown languages as ruby
4-
language: c
1+
language: rust
2+
rust: 0.12.0
53
env:
64
global:
75
- secure: YuWDOwPGprL6PiBZVeGaLOCHHgC18fQ6nq617tlt7XFCkG17r/xDWq3iiAyNxNUcwsD9CkWi5aXok8SlX3rQx84XC/sya2bi0+8Frt9EztcVxgMwWuX3Ll4mFHO7HnMhazoQYRPd0b0w4s7bFY2WidxCqjsMKRgAM26Gn+6oQto=
8-
install:
9-
- curl https://static.rust-lang.org/rustup.sh | sudo sh -
10-
- rustc --version
116
script:
12-
- make clean test
7+
- rustc --version
8+
- make all
139
after_script:
1410
- make docs
1511
- curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh

api-collections-hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
// running the same for the second time, will add +1 to "foo"
2929
h.insert_or_update_with("foo", 1, |_k, v| *v += 1);
3030
println!("foo={}", h.get(&("foo")));
31-
assert_eq!(*h.get(&("foo")), 43);
31+
assert_eq!(h["foo"], 43);
3232

3333
// You don't actually need the HashMap to own the keys (but
3434
// unless all keys are static, this will be likely to lead

design_pattern-chain_of_command.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! Example of design pattern inspired from PHP code of
66
//! http://codersview.blogspot.fr/2009/05/chain-of-command-pattern-using-php.html
77
//!
8-
//! Tested with rust-0.12-pre
8+
//! Tested with rust-0.12
99
//!
1010
//! @author Eliovir <http://github.com/~eliovir>
1111
//!
@@ -17,14 +17,14 @@ trait Command {
1717
fn on_command(&self, name: &str, args: &[&str]);
1818
}
1919

20-
struct CommandChain {
21-
commands: Vec<Box<Command>>,
20+
struct CommandChain<'a> {
21+
commands: Vec<Box<Command + 'a>>,
2222
}
23-
impl CommandChain {
24-
fn new() -> CommandChain {
23+
impl<'a> CommandChain<'a> {
24+
fn new() -> CommandChain<'a> {
2525
CommandChain{commands: Vec::new()}
2626
}
27-
fn add_command(&mut self, command: Box<Command>) {
27+
fn add_command(&mut self, command: Box<Command + 'a>) {
2828
self.commands.push(command);
2929
}
3030
fn run_command(&self, name: &str, args: &[&str]) {

design_pattern-command.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![desc = "Example of design pattern inspired from Head First Design Patterns"]
55
//! Example of design pattern inspired from Head First Design Patterns
66
//!
7-
//! Tested with rust-0.12-pre
7+
//! Tested with rust-0.12
88
//!
99
//! @author Eliovir <http://github.com/~eliovir>
1010
//!
@@ -76,14 +76,14 @@ impl Command for LightOffCommand {
7676
}
7777

7878
// The command will be launched by a remote control.
79-
struct SimpleRemoteControl {
80-
command: Box<Command>,
79+
struct SimpleRemoteControl<'a> {
80+
command: Box<Command + 'a>,
8181
}
82-
impl SimpleRemoteControl {
83-
fn new() -> SimpleRemoteControl {
82+
impl<'a> SimpleRemoteControl<'a> {
83+
fn new() -> SimpleRemoteControl<'a> {
8484
SimpleRemoteControl { command: box NullCommand::new() }
8585
}
86-
fn set_command(&mut self, cmd: Box<Command>) {
86+
fn set_command(&mut self, cmd: Box<Command + 'a>) {
8787
self.command = cmd;
8888
}
8989
fn button_was_pressed(&self) {
@@ -94,12 +94,12 @@ impl SimpleRemoteControl {
9494
fn main() {
9595
let mut remote = SimpleRemoteControl::new();
9696
let light = Light::new();
97-
let lightOn = LightOnCommand::new(light);
98-
let lightOff = LightOffCommand::new(light);
97+
let light_on = LightOnCommand::new(light);
98+
let light_off = LightOffCommand::new(light);
9999

100100
remote.button_was_pressed();
101-
remote.set_command(box lightOn);
101+
remote.set_command(box light_on);
102102
remote.button_was_pressed();
103-
remote.set_command(box lightOff);
103+
remote.set_command(box light_off);
104104
remote.button_was_pressed();
105105
}

design_pattern-decorator.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![comment = "Implement in Rust the design pattern found in Wikipedia (PHP example)."]
66
//! Design pattern: Decorator
77
//!
8-
//! Tested with rust-0.10-pre
8+
//! Tested with rust-0.12
99
//!
1010
//! @see http://fr.wikipedia.org/wiki/D%C3%A9corateur_%28patron_de_conception%29#Exemple_en_PHP
1111
//!
@@ -36,10 +36,11 @@ struct UnderlinedMessage<T> {
3636
impl<T:Printable> Printable for UnderlinedMessage<T> {
3737
fn print(&self) -> String {
3838
// http://doc.rust-lang.org/std/str/trait.StrSlice.html#tymethod.char_len
39-
let message = self.decorated.print();
39+
let mut message = self.decorated.print();
4040
let length = message.len();
41-
message.append("\n")
42-
.append("=".repeat(length).as_slice())
41+
message.push_str("\n");
42+
message.push_str("=".repeat(length).as_slice());
43+
message
4344
}
4445
}
4546

@@ -49,9 +50,9 @@ struct IndentedMessage<T> {
4950

5051
impl<T:Printable> Printable for IndentedMessage<T> {
5152
fn print(&self) -> String {
52-
let message = self.decorated.print();
53-
message.append(" ")
54-
.replace("\n", "\n ")
53+
let mut message = self.decorated.print();
54+
message.push_str(" ");
55+
message.replace("\n", "\n ")
5556
}
5657
}
5758

design_pattern-decorator2.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![desc = "Example of design pattern inspired from Head First Design Patterns"]
55
//! Example of design pattern inspired from Head First Design Patterns
66
//!
7-
//! Tested with rust-0.12-pre
7+
//! Tested with rust-0.12
88
//!
99
//! @author Eliovir <http://github.com/~eliovir>
1010
//!
@@ -43,12 +43,15 @@ struct Ingredient<'a> {
4343
description: &'a str,
4444
price: f64,
4545
// to decorate an struct, it must have the common trait
46-
drink: Box<Drinkable>,
46+
drink: Box<Drinkable + 'a>,
4747
}
4848

4949
impl<'a> Drinkable for Ingredient<'a> {
5050
fn description(&self) -> String {
51-
self.drink.description().append(", ").append(self.description)
51+
let mut description = self.drink.description();
52+
description.push_str(", ");
53+
description.push_str(self.description);
54+
description.clone()
5255
}
5356
fn price(&self) -> f64 {
5457
self.price + self.drink.price()
@@ -57,7 +60,7 @@ impl<'a> Drinkable for Ingredient<'a> {
5760

5861
impl<'a> Ingredient<'a> {
5962
// The "constructor", optional but useful!
60-
pub fn new(description: &'a str, price: f64, drink: Box<Drinkable>) -> Ingredient<'a> {
63+
pub fn new(description: &'a str, price: f64, drink: Box<Drinkable + 'a>) -> Ingredient<'a> {
6164
Ingredient { description: description, price: price, drink: drink }
6265
}
6366
}

design_pattern-observer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait Observable<'a, T: Observer> {
3030
struct Display {
3131
name: String,
3232
}
33-
struct Weather<'a, T> {
33+
struct Weather<'a, T:'a> {
3434
temperature: f64,
3535
observers: Vec<&'a T>
3636
}

design_pattern-strategy.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ impl FlyBehaviour for DoNotFly {
3535
}
3636

3737
// The object has reference to the variation.
38-
struct Duck {
39-
flyBehaviour: Box<FlyBehaviour>,
38+
struct Duck<'a> {
39+
fly_behaviour: Box<FlyBehaviour + 'a>,
4040
}
4141

42-
impl Duck {
42+
impl<'a> Duck<'a> {
4343
// a method calls the funciton in the variation.
4444
fn fly(&self) {
45-
self.flyBehaviour.fly();
45+
self.fly_behaviour.fly();
4646
}
47-
fn set_fly_behaviour(&mut self, flyBehaviour: Box<FlyBehaviour>) {
48-
self.flyBehaviour = flyBehaviour;
47+
fn set_fly_behaviour(&mut self, fly_behaviour: Box<FlyBehaviour + 'a>) {
48+
self.fly_behaviour = fly_behaviour;
4949
}
5050
}
5151

5252
fn main() {
5353
let dnf = DoNotFly;
5454
let fww = FlyWithWings;
55-
let mut ducky = Duck { flyBehaviour: box fww };
55+
let mut ducky = Duck { fly_behaviour: box fww };
5656
ducky.fly();
5757
// so functions can change dynamically
5858
ducky.set_fly_behaviour(box dnf);

lang-pointers.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(managed_boxes)]
21
extern crate debug;
32
use std::rc::Rc;
4-
use std::gc::GC;
53

64
/**
75
* Snippets from the Dave Herman's presentation (2013-01-06)
@@ -47,51 +45,33 @@ fn main() {
4745
// &T, in C++ : T&
4846
let p = Point{x:1.1, y:1.2};
4947
print_point(&p);
50-
// Managed pointer to T
51-
// @T, in C++ : shared_ptr<T>
52-
// The type syntax @T was replaced by Gc<T> which lives in std::gc.
53-
let p2 = box(GC) Point{x:2.1, y:2.2};
54-
print_point(&*p2);
5548
// Owned pointer to T
5649
// box T, in C++ : unique_ptr<T>
5750
let p3 = box Point{x:3.1, y:3.2};
5851
print_point(&*p3);
59-
// Unsafe pointer to T
60-
// *T
61-
/*
62-
let p4; // uninitialized
63-
print_point(p4); // error
64-
65-
let p5 = ~Point {x:5.1, y:5.2};
66-
box.topLeft = move p5; // deinitialized
67-
print_point(p); // error
68-
*/
6952

7053
/*
7154
* 13. Dereferencing pointers
7255
* http://doc.rust-lang.org/tutorial.html#dereferencing-pointers
7356
*/
74-
let managed = box(GC) 10i;
75-
let owned = box 20;
76-
let borrowed = &30;
57+
let owned = box 20u;
58+
let borrowed = &30u;
7759

78-
let sum = *managed + *owned + *borrowed;
79-
println!("{} + {} + {} = {}", *managed, *owned, *borrowed, sum);
60+
let sum = *owned + *borrowed;
61+
println!("{} + {} = {}", *owned, *borrowed, sum);
8062

8163
/*
8264
* Dereferenced mutable pointers may appear on the left hand side of assignments.
8365
* Such an assignment modifies the value that the pointer points to.
8466
*/
85-
let managed = box(GC) 10i;
86-
let mut owned = box 20;
67+
let mut owned = box 20u;
8768

88-
let mut value = 30;
69+
let mut value = 30u;
8970
let borrowed = &mut value;
9071

9172
*owned = *borrowed + 100;
92-
*borrowed = *managed + 1000;
93-
let sum = *managed + *owned + *borrowed;
94-
println!("{} + {} + {} = {}", *managed, *owned, *borrowed, sum);
73+
let sum = *owned + *borrowed;
74+
println!("{} + {} = {}", *owned, *borrowed, sum);
9575

9676
/*
9777
* Pointers have high operator precedence, but lower precedence than the dot
@@ -102,7 +82,7 @@ fn main() {
10282
* dereferencing to the receiver (the value on the left-hand side of the dot),
10383
* so in most cases, explicitly dereferencing the receiver is not necessary.
10484
*/
105-
let bottom = box(GC) Point { x: 10.0, y: 120.0 };
85+
let bottom = box Point { x: 10.0, y: 120.0 };
10686
let top = box Point { x: bottom.x + 100.0, y: bottom.y - 100.0 };
10787
let rect = &Rectangle(*top, *bottom);
10888
let area = rect.area();
@@ -118,8 +98,4 @@ fn main() {
11898
let rc1 = Rc::new(1u);
11999
let rc2 = rc1.clone();
120100
println!("{:u}", *(rc1.deref()) + *(rc2.deref()));
121-
122-
let gc1 = box(GC) 1u;
123-
let gc2 = gc1.clone();
124-
println!("{:u}", *gc1 + *gc2);
125101
}

tutorial-04_2-pattern-matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
match my_number {
3838
0 => println!("zero"),
3939
1 | 2 => println!("one or two"),
40-
3..10 => println!("three to ten"),
40+
3...10 => println!("three to ten"),
4141
_ => println!("something else")
4242
}
4343
/*
@@ -53,7 +53,7 @@ fn main() {
5353
let age: uint = rng.gen_range(0u, 100);
5454
println!("age = {}", age);
5555
match age {
56-
a @ 0..20 => println!("{} years old", a),
56+
a @ 0...20 => println!("{} years old", a),
5757
_ => println!("older than 21")
5858
}
5959

tutorial-17-generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ fn map<T, U>(vector: &[T], function: |v: &T| -> U) -> Vec<U> {
1414
}
1515
fn main() {
1616
let strings = ["a", "b", "c"];
17-
let new_strings = map(strings, |&x| x.to_string().append(x));
17+
let new_strings = map(strings, |&x| { let mut msg = x.to_string(); msg.push_str(x); msg });
1818
println!("{} -> {}", strings.as_slice(), new_strings);
1919
}

tutorial-tasks-02_2-backgrounding_computations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
let mut futures = Vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
4141

4242
let mut final_res = 0f64;
43-
for ft in futures.mut_iter() {
43+
for ft in futures.iter_mut() {
4444
final_res += ft.get();
4545
}
4646
println!("π^2/6 is not far from : {}", final_res);

0 commit comments

Comments
 (0)