Skip to content

Instantly share code, notes, and snippets.

@jmcarthur
Created September 28, 2013 19:53
Show Gist options
  • Save jmcarthur/6745884 to your computer and use it in GitHub Desktop.
Save jmcarthur/6745884 to your computer and use it in GitHub Desktop.
A little experiment that has led to a question about lifetimes in Rust.
struct Thunk<'a, T> {
f : ~fn() -> & 'a T
}
@jmcarthur
Copy link
Author

hello.rs:2:22: 2:23 error: Illegal lifetime 'a: this lifetime must be declared
hello.rs:2 f : ~fn() -> & 'a T

@jmcarthur
Copy link
Author

struct Thunk {
f : ~fn<'a> (& 'a mut Thunk) -> & 'a T
}

@jmcarthur
Copy link
Author

impl Thunk {
fn force <'a> (& 'a mut self) -> & 'a T {
return (self.f) (self);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment