Skip to content

Instantly share code, notes, and snippets.

Sven Nilsen bvssvni

Block or report user

Report or block bvssvni

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:8241479
fn add<T: Add<T, T>>(
a: proc() -> T,
b: proc() -> T
) -> proc() -> T {
proc() a() + b()
}
fn main() {
let a = proc() 2;
let b = proc() 3;
View gist:8251339
/// Expr wraps a 'proc' that computes a value and a new expression state.
pub struct Expr<T, Env> {
/// Runs the expression and computes the new expression state.
run: proc(&mut Env) -> (T, Expr<T, Env>)
}
pub fn run<Env, V>(env: &mut Env, expr: &mut Expr<V, Env>) -> V {
let (v, n) = (expr.run)(env);
expr.run = n.run;
v
View gist:8251925
#[feature(macro_rules)]
extern mod expr;
macro_rules! run(
($expr:expr $env:expr) => {
let (v, n) = (expr.run)(&mut env);
expr = n;
v
}
View gist:8294063
enum TodoList {
}
pub fn todo(task: TodoList) -> bool {
match task {
}
}
View gist:8414419
/// Executes a list of expressions.
pub fn exec<Env>(mut a: ~[Expr<(), Env>]) -> Expr<(), Env> {
Expr {
run: proc(env: &mut Env) {
for i in range(0, a.len()) {
let (_, exn) = (a[i].run)(env);
a[i] = exn;
}
((), exec(a))
}
View gist:8431723
error: wrong number of type arguments: expected 1 but found 2
/home/sven/Desktop/cgmath-rs/src/cgmath/dual.rs:38 impl<S: Primitive> Vector<S, [S, ..2]> for Dual<S> {}
^~~~~~~~~~~~~~~~~~~
View gist:8625865
pub struct Player {
name: ~str
}
pub struct Enemy {
name: ~str
}
pub trait Entity {
View gist:8631956
/*
Tests the Any trait.
*/
pub struct Player {
name: ~str
}
View gist:8633182
#[inline]
fn as_ref<'a, T: 'static>(a: &'a Entity) -> Option<&'a T> {
if TypeId::of::<T>() == TypeId::of::<&'static Entity>() {
Some(unsafe { transmute(a.as_void_ptr()) })
} else {
None
}
}
View gist:8659736
fn type_name<T>(_: &T) -> &'static str {
unsafe { (*::std::unstable::intrinsics::get_tydesc::<T>()).name }
}
// USAGE
println!("{}", type_name(&x));
You can’t perform that action at this time.