Skip to content

Instantly share code, notes, and snippets.

View eddyb's full-sized avatar

Eduard-Mihai Burtescu eddyb

View GitHub Profile
@eddyb
eddyb / test.rs
Last active August 29, 2015 13:57
type ParseResult<S, R> = Result<(R, ~[S]), ~str>;
enum Parser<'a, S, R> {
Parser('a |&[S]| -> ~[ParseResult<S, R>])
}
fn main() {
let p = Parser(/* missing argument here */);
println!("test");
}
@eddyb
eddyb / test.rs
Last active August 29, 2015 13:57
mod config {
pub enum Node<T> {
Directory(~str, ~[Node<T>]),
Entry(~str, T)
}
impl<T> Node<T> {
pub fn add(&mut self, entry: Node<T>) -> bool {
match *self {
Directory(_, ref mut list) => { list.push(entry); true }
@eddyb
eddyb / test.rs
Last active August 29, 2015 13:57
mod config {
pub enum Node<T> {
Directory(~str, ~[Node<T>]),
Entry(~str, T)
}
impl<T> Node<T> {
pub fn add(&mut self, entry: Node<T>) -> Option<&mut self> {
let succeeded = match *self {
Directory(_, ref mut list) => { list.push(entry); true }
struct Blob<HEADER> {
data:~[u8],
}
impl<T> std::ops::Deref<T> for Blob<T> {
fn deref<'s>(&'s self)->&'s T {
//assert!(self.num_bytes() > std::intrinsics::size_of::<T>());
unsafe { &*(&self.data[0] as *u8 as *T)
}
@eddyb
eddyb / insts.rs
Last active August 29, 2015 14:00 — forked from anonymous/insts
0: Split(1, 5)
1: OneChar(a, 0)
2: CharClass([(b, c)], 0)
3: OneChar(d, 0)
4: Match
5: OneChar(r, 0)
6: Split(5, 7)
7: Match
static NTASKS: uint = 10;
fn main() {
let mut array = [0u, ..NTASKS];
for (x, i) in array.mut_iter().enumerate() {
let ptr = x as *mut _;
spawn(proc() {
let inner_x = unsafe {&mut *ptr};
#![crate_id = ""]
#![deny(missing_doc)]
#![feature(macro_rules)]
//! Documentation goes here.
extern crate openssl;
extern crate serialize;
use std::io;
fn linked_face(vertexes: &[Rc<RefCell<Vertex>>], face: UnlinkedFace) -> Option<RefCell<Face>> {
Some(RefCell::new(Face {
a: match vertexes.get(face.a) {
Some(x) => x.clone(),
None => return None
},
b: match vertexes.get(face.b) {
Some(x) => x.clone(),
None => return None
},
@eddyb
eddyb / material.rs
Last active August 29, 2015 14:05 — forked from anonymous/material.rs
use std::num::zero;
use std::rand::Rng;
use std::rand::distributions::range::SampleRange;
use vecmath::vector::Vec3;
use vecmath::ray::Ray;
use lightray::Lightray;
use objecthit::ObjectHit;
@eddyb
eddyb / dom-thin.rs
Last active August 29, 2015 14:06 — forked from jdm/gist:9900569
// <core>
#[lang="vtable"]
struct Vtable<T, Sized? Trait>(&'static (unsafe fn(*mut T), uint, uint));
extern "rust-intrinsic" { fn get_vtable<T, Sized? Trait>() -> Vtable<T, Trait>; }
#[lang="has_vtable"]
trait HasVtable<T, Sized? Trait> {}
// </core>
#[repr(fixed, inline_vtable)]
trait Node: Any {