Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created March 7, 2014 07:29
Show Gist options
  • Save shadowmint/9406982 to your computer and use it in GitHub Desktop.
Save shadowmint/9406982 to your computer and use it in GitHub Desktop.
Rust oddness
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