This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rust-git | |
[thestinger] | |
SigLevel = Optional | |
Server = http://pkgbuild.com/~thestinger/repo/$arch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut w = std::io::BufferedWriter::new(std::io::stdio::stdout()); | |
for _ in range(0, 256) { | |
w.write_char('b'); | |
} | |
w.flush(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
println!("{:i}", sum([1,2,3,4,5])); | |
} | |
fn sum(x: &[int]) -> int { | |
match x { | |
[head, ..tail] => sum(tail) + head, | |
[] => 0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::iter::Unfold; | |
fn main() { | |
for fib in (0,1).unfold(next).take(20) { | |
println!("{}", fib); | |
}; | |
} | |
fn next(arg: &mut (int, int)) -> Option<int> { | |
let (lo, hi) = *arg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::iter::Unfold; | |
fn main() { | |
for fib in next.unfold((0,1)).take(20) { | |
println!("{}", fib); | |
}; | |
} | |
fn next(arg: &mut (int, int)) -> Option<int> { | |
let (lo, hi) = *arg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::iter::Unfold; | |
fn next(arg: &mut (int, int)) -> Option<int> { | |
let (lo, hi) = *arg; | |
*arg = (hi, lo + hi); | |
Some(lo) | |
} | |
fn main() { | |
for fib in Unfold::new((0,1), next).take(20) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
a: (int, int) | |
} | |
fn main() { | |
let foo = Foo { a: (1, 2) }; | |
let Foo { a: (x, y) } = foo; | |
println!("{} {}", x, y); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This program defines a recursive datastructure and implements methods upon it. | |
Recursive datastructures require a layer of indirection, which is provided here | |
by a unique pointer, indicated by the tilde `~` operator. These are analogous to | |
the C++ library type `std::unique_ptr`, though with more static safety guarantees. */ | |
fn main() { | |
let list = ~Node(1, ~Node(2, ~Node(3, ~Empty))); | |
println!("Sum of all values in the list: {:i}.", list.multiply_by(2).sum()); | |
} | |
// An `enum` defines a type that may be one of several different kinds of values at runtime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let argv = std::os::args(); | |
let (x, y, z) = match argv { | |
[filename, arg1, arg2, arg3, ..rest] => (arg1, arg2, arg3), | |
_ => fail!("At least three arguments expected.") | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn integral(f: &|f32|->f32, p: u32, a: f32, b: f32) -> f32 { | |
if p == 1 { | |
(b-a) * ((*f)(a) + 4.0 * (*f)((a+b)/2.0) + (*f)(b))/6.0 | |
} | |
else { | |
let mid = (a+b)/2.0; | |
integral(f, p-1, a, mid) + integral(f, p-1, mid, b) | |
} | |
} |