Skip to content

Instantly share code, notes, and snippets.

Avatar

bstrie bstrie

View GitHub Profile
View pyon.rs
fn main() {
println!("{:i}", sum([1,2,3,4,5]));
}
fn sum(x: &[int]) -> int {
match x {
[head, ..tail] => sum(tail) + head,
[] => 0
}
}
View taneb2.rs
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;
View taneb3.rs
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;
View taneb.rs
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) {
View gist:8979798
rust-git
[thestinger]
SigLevel = Optional
Server = http://pkgbuild.com/~thestinger/repo/$arch
View buf.rs
fn main() {
let mut w = std::io::BufferedWriter::new(std::io::stdio::stdout());
for _ in range(0, 256) {
w.write_char('b');
}
w.flush();
}
View um.rs
fn main() {
let mut pixels = [0f32, ..8];
for &mut pixel in pixels.mut_iter() {
pixel = 2.0;
}
println!("{:?}", pixels); // [0f32, 0f32, 0f32, 0f32, 0f32, 0f32, 0f32, 0f32]
}
View perx.rs
use std::f32::consts::PI;
use std::io::{BufferedWriter, stdout};
use std::rand::{Rng, StdRng};
struct Vec2 {
x: f32,
y: f32,
}
fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v }
View repr.rs
repr.rs:5:5: 5:15 error: discriminant value outside specified type
repr.rs:5 Qux = 5000
^~~~~~~~~~
repr.rs:1:8: 1:10 note: discriminant type specified here
repr.rs:1 #[repr(i8)]
^~
View um.rs
fn foo<T, U>(x: T) -> U {
x // error: mismatched types: expected `U` but found `T` (expected type parameter but found type parameter)
}
fn main() {
foo(1u);
}