This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | struct Monster { | |
| damage: int | |
| } | |
| impl Monster { | |
| fn attack(&self) -> int { | |
| return self.damage; // Why do I have to use a return here? | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fn unwrap(f: &fn() -> Option<int>) -> Option<int>{ | |
| f() | |
| } | |
| fn main() { | |
| let c = unwrap(|| { | |
| let a = Some(2); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | enum Expression{ | |
| Number(int), | |
| Add(Option<~Expression>,Option<~Expression>), | |
| Mult(Option<~Expression>,Option<~Expression>), | |
| Div(Option<~Expression>,Option<~Expression>), | |
| Sub(Option<~Expression>,Option<~Expression>) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | enum Expression{ | |
| Number(int), | |
| Add(~Expression,~Expression), | |
| Sub(~Expression,~Expression), | |
| } | |
| fn eval(e: Expression) -> int { | |
| match e { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | struct Number{ | |
| mut i: int | |
| } | |
| impl Number { | |
| fn mult(&mut self) -> &mut Number{ | |
| self.i *= 2; | |
| self | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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) {} | |
| } | 
OlderNewer