Skip to content

Commit 01757aa

Browse files
committed
Merge branch 'master' of github.com:eliovir/rust-examples
2 parents 72ed7b5 + 8ece03f commit 01757aa

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TESTPROG:=$(patsubst %.rs,test-%,$(TESTSRC))
66
SRC=$(wildcard *.rs)
77
SRC:=$(filter-out $(TESTSRC),$(SRC))
88
PROG:=$(patsubst %.rs,%,$(SRC))
9-
RUSTFLAGS= -L .
9+
RUSTFLAGS=
1010

1111
.SILENT:
1212
.PRECIOUS: $(LIBSTAMP)
@@ -37,7 +37,10 @@ test: $(TESTPROG)
3737
./$$EXE;\
3838
done
3939

40-
% : %.rs $(LIBSTAMP)
40+
tutorial-tasks-02_2-backgrounding_computations: tutorial-tasks-02_2-backgrounding_computations.rs $(LIBSTAMP)
41+
$(RUSTC) $(RUSTFLAGS) $< -o $@ -L .
42+
43+
% : %.rs
4144
$(RUSTC) $(RUSTFLAGS) $< -o $@
4245

4346
lib-stamps/% : %.rs

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ Examples are tested with version 0.7.
1616
* 3 Syntax basics: `tutorial-03-syntax_basics.rs`
1717
* 4.3 Loops (`for`, `for i.times`, `while`, `loop`): `tutorial-04_3-loops.rs`
1818
* 5.2 Enums: `tutorial-05_2-enum.rs`
19+
* 5.3 Tuples: `tutorial-05_3-tuples.rs`
1920
* [Rust Tasks and Communication]
2021
* 2 Basics: `tutorial-tasks-02-basics.rs`
2122
* 2.1 Communication: `tutorial-tasks-02_1-communication.rs`
2223
* 2.2 Backgrounding computations: Futures: `tutorial-tasks-02_2-backgrounding_computations.rs`
2324
* [Doc unit testing]
2425
* Unit testing in Rust: `unittests.rs`
2526
* API
26-
* Program to an 'interface', not an 'implementation', by Josh Davis: `lang-interface.rs`
27+
* Program to an 'interface', not an 'implementation', by [Josh Davis](http://joshldavis.com/2013/07/01/program-to-an-interface-fool/): `lang-interface.rs`
2728
* Pointer snippets from Dave Herman's talk: `lang-pointers.rs`
2829
* extra::getopts: `api-extra-getopts.rs`
2930
* std::hashmap::HashMap: `api-std-hashmap.rs`

api-std-hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn main() {
1212
println(fmt!("Is there a key foo? => %?", h.contains_key(& &"foo"))); // => true
1313
println(fmt!("Is there a key baz? => %?", h.contains_key(& &"baz"))); // => false
1414
println(fmt!("The value for foo is => %?", h.find(& &"foo"))); // => Some(&42)
15+
let key = "baz";
1516
h.insert(key, 1);
1617
println(fmt!("Is there a key baz? => %?", h.contains_key(& &"baz"))); // => false
1718

@@ -25,7 +26,6 @@ fn main() {
2526
println(fmt!("Is there a key foo? => %?", h.contains_key(&~"foo"))); // => true
2627
println(fmt!("Is there a key baz? => %?", h.contains_key(&~"baz"))); // => false
2728
println(fmt!("The value for foo is => %?", h.find(&~"foo"))); // => Some(&42)
28-
let key = "baz";
2929
h.insert(key.to_owned(), 1);
3030
println(fmt!("Is there a key baz? => %?", h.contains_key(&~"baz"))); // => true
3131
}

tutorial-05_3-tuples.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 5.3 Tuples
3+
* http://static.rust-lang.org/doc/0.7/tutorial.html#tuples
4+
*
5+
* @license MIT license <http://www.opensource.org/licenses/mit-license.php>
6+
*/
7+
fn main() {
8+
// A Tuple is an immutable fixed-size collection of values.
9+
10+
let tuple0 = ();
11+
println(fmt!("%?", tuple0));
12+
13+
let mytup: (int, int, float) = (10, 20, 30.0);
14+
match mytup {
15+
(a, b, c) => info!(a + b + (c as int))
16+
}
17+
18+
let tuple1 = (5i, 6i);
19+
let (first, _) = tuple1;
20+
println(first.to_str());
21+
}

0 commit comments

Comments
 (0)