Last active
March 22, 2017 14:04
-
-
Save barafael/93f4bf1d2bb18b1532b5c36b303335aa to your computer and use it in GitHub Desktop.
Simplified rust ownership problem
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
mod timesheet; | |
fn main() { | |
let mut ts = timesheet::Session::new(); | |
println!("{:?}", ts); | |
} |
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
#[derive(Debug)] | |
pub enum Event { | |
Pause, | |
Meta { text: String }, | |
Commit { hash: u64 }, | |
} | |
#[derive(Debug)] | |
pub struct Session { | |
pub id: u64, | |
events: Vec<Event>, | |
} | |
impl Session { | |
pub fn new() -> Session { | |
Session { | |
id: 0, | |
events: Vec::<Event>::new(), | |
} | |
} | |
pub fn append_event(&mut self, e: Event) { | |
match e { | |
Event::Pause => self.events.push(e), | |
Event::Meta { .. } => self.events.push(e), | |
Event::Commit { hash } => println!("Commit hash: {}", hash), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment