Skip to content

Instantly share code, notes, and snippets.

Created July 12, 2017 19:34
Show Gist options
  • Save anonymous/7ae98b6d09196a7cc0565edbd7eec940 to your computer and use it in GitHub Desktop.
Save anonymous/7ae98b6d09196a7cc0565edbd7eec940 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::cell::RefCell;
struct Foo<'a> {
items: Vec<u8>,
cur_item: RefCell<Option<&'a u8>>
}
impl<'a> Foo<'a> {
fn mutate(&mut self) {}
}
fn main() {
let mut foo = Foo {
items: vec![0],
cur_item: RefCell::new(None),
};
*foo.cur_item.borrow_mut() = Some(&foo.items[0]);
foo.mutate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment