Skip to content

Instantly share code, notes, and snippets.

@jpace121
Last active August 29, 2015 14:24
Show Gist options
  • Save jpace121/42b51e6751f44cfe51d9 to your computer and use it in GitHub Desktop.
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...
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);
}
//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