Last active
August 29, 2015 14:24
-
-
Save jpace121/42b51e6751f44cfe51d9 to your computer and use it in GitHub Desktop.
Some random stuff I tried when I realized I hadn't written any rust in a while...
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 std::fmt; | |
| struct Meter(u32); | |
| impl fmt::Display for Meter{ | |
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
| write!(f,"{}",self.0) | |
| } | |
| } | |
| fn add(a:u32,b:u32) -> u32 { | |
| a + b | |
| } | |
| fn steal(a:&Meter){ | |
| println!("{}",a); | |
| } | |
| fn main() { | |
| let a = Meter(2); | |
| steal(&a); | |
| steal(&a); | |
| } |
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 Meter {Meter(u32),} | |
| struct Meter(u32); | |
| fn add(a:u32,b:u32) -> u32 { | |
| a+b | |
| } | |
| fn main() { | |
| let a : Meter = Meter(2); | |
| let b: Meter = Meter(1); | |
| println!("{}",add(1,2)); | |
| //let c:Meter = add(a,b); //this is an obvious type error | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment