Created
March 7, 2014 07:29
-
-
Save shadowmint/9406982 to your computer and use it in GitHub Desktop.
Rust oddness
This file contains 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 crate uuid; | |
use uuid::Uuid; | |
use std::fmt; | |
struct BlahLF { | |
id: Uuid | |
} | |
struct StateLF; | |
impl BlahLF { | |
fn new() -> ~BlahLF { | |
let id = Uuid::new_v4(); | |
println!("Created: {}", id); | |
return ~BlahLF { id: id }; | |
} | |
} | |
impl fmt::Show for BlahLF { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
return write!(f.buf, "<BlahLF:: {}>", self.id); | |
} | |
} | |
impl Drop for BlahLF { | |
fn drop(&mut self) { | |
//println!("Dropped element: {}", self); | |
} | |
} | |
#[test] | |
fn test_lifetime_scope() { | |
let x = BlahLF::new(); | |
let mut y = BlahLF::new(); | |
let mut z = &BlahLF::new(); | |
println!("{}", x); | |
println!("{}", y); | |
println!("{}", z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment