Skip to content

Instantly share code, notes, and snippets.

@barafael
Last active March 22, 2017 14:04
Show Gist options
  • Save barafael/93f4bf1d2bb18b1532b5c36b303335aa to your computer and use it in GitHub Desktop.
Save barafael/93f4bf1d2bb18b1532b5c36b303335aa to your computer and use it in GitHub Desktop.
Simplified rust ownership problem
mod timesheet;
fn main() {
let mut ts = timesheet::Session::new();
println!("{:?}", ts);
}
#[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