Skip to content

Instantly share code, notes, and snippets.

@MarkJr94
MarkJr94 / chain1.rs
Created May 31, 2013 18:54
Simple Chain outline
fn add_one(n: int) ⟶  int {
n + 1
}
fn times_two(n: int) ⟶  int {
n * 2
}
fn chain<A,B,C>(f1: ~fn(a: A) ⟶  B,f2: ~fn(b: B) ⟶  C) ⟶  ~fn(A) ⟶  C {
|x: A| {
@MarkJr94
MarkJr94 / chain2.rs
Created May 31, 2013 19:15
Simple chain outline
use core::from_str::*;
fn stringify<T: ToStr>(x: T) ⟶  ~str {
x.to_str()
}
fn unstringify<T: FromStr> (s: ~str) ⟶  Option<T> {
FromStr::from_str(s)
}
@MarkJr94
MarkJr94 / chain3_no_unicode.rs
Created May 31, 2013 19:23
Simple Chain outline
use core::from_str::*;
fn stringify<T: ToStr>(x: T) -> ~str {
x.to_str()
}
fn unstringify<T: FromStr> (s: ~str) -> Option<T> {
FromStr::from_str(s)
}
fn empty_vec<T>() -> ~[T] {
let v: ~[T] = ~[];
v
}
fn main() {
let mut v_int = empty_vec<int>();
let mut v_float = empty_vec<float>();
}
use std::libc::size_t;
static LONG: int = 0;
static OBJECTPOINT: int = 10_000;
static FUNCTIONPOINT: int = 20_000;
static OFF_T: int = 30_000;
macro_rules! CINIT(
($name:ident $typ:ident $val:expr) => (
$name = $typ + $val
#[deriving(Eq,Rand)]
pub enum Card {
One = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
// listen.rs
use extra::net::ip;
use extra::net::tcp;
use std::task;
pub fn server_loop() {
use extra::uv::iotask::spawn_iotask;
let mut builder = task::task();
// mummy.rs
use pc::PC;
use common::{Character};
#[deriving(ToStr)]
pub struct Mummy {
hp: uint,
attack: uint,
x: int,
@MarkJr94
MarkJr94 / minimal_borrowck.rs
Created June 28, 2013 21:57
Minimal example of problem with borrowck, mutability, and trait objects.
// traitfail.rs
trait Slide {
fn new(x: int) -> Self;
fn x_mut<'r> (&'r mut self) -> &'r mut int;
fn x(&self) -> int;
}
struct Bead {
x: int
// curl/opt.rs
macro_rules! CINIT(
($name:ident, $typ:expr, $val:expr) => (
$name = $typ + $val,
)
)
static LONG: i32 = 0i32;