Skip to content

Instantly share code, notes, and snippets.

@sdleffler
Created May 27, 2017 01:02
Show Gist options
  • Save sdleffler/49f2adcb5adcac4398a248addef844e7 to your computer and use it in GitHub Desktop.
Save sdleffler/49f2adcb5adcac4398a248addef844e7 to your computer and use it in GitHub Desktop.
pub fn make_mut<'b>(this: &'b mut RcThunk<'a, T>) -> &'b mut T where T: Clone {
// No, moving it into a temp doesn't help. We just have to trust the CSE
// pass here.
if Rc::get_mut(&mut this.0).is_some() {
return &mut **Rc::get_mut(&mut this.0).unwrap();
}
let new_rc = Rc::new(Thunk::computed((*this.0).clone()));
this.0 = new_rc;
RcThunk::get_mut(this).unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment