Created
May 28, 2017 22:38
-
-
Save sdleffler/bd93ff6eedbbbebf9c3cbf684b2a60e0 to your computer and use it in GitHub Desktop.
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
impl<T> LazyRef for Thunk<T> { | |
#[inline] | |
fn defer<'a, F: FnBox() -> T + 'a>(f: F) -> Thunk<T> | |
where T: 'a | |
{ | |
let thunk = | |
unsafe { Box::from_raw(Box::into_raw(Box::new(f)) as *mut (FnBox() -> T + 'static)) }; | |
Thunk { | |
flag: Cell::new(Flag::Deferred), | |
data: UnsafeCell::new(Cache { deferred: thunk }), | |
} | |
} | |
#[inline] | |
fn force(&self) { | |
match self.flag.get() { | |
Flag::Deferred => { | |
unsafe { | |
(*self.data.get()).evaluate_thunk(); | |
} | |
self.flag.set(Flag::Evaluated); | |
} | |
Flag::Evaluated => {} | |
Flag::Empty => unsafe { unreachable() }, | |
} | |
} | |
} | |
error[E0310]: the parameter type `F` may not live long enough | |
--> src/unsync.rs:144:36 | |
| | |
144 | unsafe { Box::from_raw(Box::into_raw(Box::new(f)) as *mut (FnBox() -> T + 'static)) }; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| | |
= help: consider adding an explicit lifetime bound `F: 'static`... | |
note: ...so that the type `F` will meet its required lifetime bounds | |
--> src/unsync.rs:144:36 | |
| | |
144 | unsafe { Box::from_raw(Box::into_raw(Box::new(f)) as *mut (FnBox() -> T + 'static)) }; | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment