Skip to content

Instantly share code, notes, and snippets.

struct Monster {
damage: int
}
impl Monster {
fn attack(&self) -> int {
return self.damage; // Why do I have to use a return here?
}
}
fn unwrap(f: &fn() -> Option<int>) -> Option<int>{
f()
}
fn main() {
let c = unwrap(|| {
let a = Some(2);
use core::comm::{stream, Chan,PortSet};
fn main() {
let p : PortSet<~str> = PortSet::new();
for 3.times {
let(receive,send) : (Port<~str>, Chan<~str>) = stream();
enum Expression{
Number,
Add(Option<Expression>,Option<Expression>),
Mult(Option<Expression>,Option<Expression>)
}
/home/maik/hello.rs:1:0: 5:1 error: illegal recursive enum type; wrap the inner value in a box to make it representable
/home/maik/hello.rs:1 enum Expression{
/home/maik/hello.rs:2 Number,
enum Expression{
Number(int),
Add(Option<~Expression>,Option<~Expression>),
Mult(Option<~Expression>,Option<~Expression>),
Div(Option<~Expression>,Option<~Expression>),
Sub(Option<~Expression>,Option<~Expression>)
}
enum Expression{
Number(int),
Add(~Expression,~Expression),
Sub(~Expression,~Expression),
}
fn eval(e: Expression) -> int {
match e {
struct Vec3<T>{
mut x: T,
mut y: T,
mut z: T
}
impl<T: Add<T,T>+Clone> Vec3<T> {
fn add(&mut self,v: Vec3<T>){
self.x += v.x.clone();
self.y += v.y.clone();
struct Vec3<T>{
mut x: T,
mut y: T,
mut z: T
}
impl<T: Add<T,T>+Clone> Vec3<T> {
fn add(&mut self,v: Vec3<T>){
self.x += v.x.clone();
self.y += v.y.clone();
struct Number{
mut i: int
}
impl Number {
fn mult(&mut self) -> &mut Number{
self.i *= 2;
self
}
extern mod extra;
struct Timer;
impl Timer {
fn sleep(time: float){
let start_time = extra::time::precise_time_s();
let wait = time;
while start_time > (extra::time::precise_time_s() - wait) {}
}