Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bvssvni's full-sized avatar

Sven Nilsen bvssvni

View GitHub Profile
fn type_name<T>(_: &T) -> &'static str {
unsafe { (*::std::unstable::intrinsics::get_tydesc::<T>()).name }
}
// USAGE
println!("{}", type_name(&x));
#[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
}
}
/*
Tests the Any trait.
*/
pub struct Player {
name: ~str
}
pub struct Player {
name: ~str
}
pub struct Enemy {
name: ~str
}
pub trait Entity {
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> {}
^~~~~~~~~~~~~~~~~~~
/// 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))
}
enum TodoList {
}
pub fn todo(task: TodoList) -> bool {
match task {
}
}
#[feature(macro_rules)]
extern mod expr;
macro_rules! run(
($expr:expr $env:expr) => {
let (v, n) = (expr.run)(&mut env);
expr = n;
v
}
/// 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
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;