Skip to content

Instantly share code, notes, and snippets.

@Wolvereness
Created August 3, 2017 00:54
Show Gist options
  • Save Wolvereness/a13982175fbc25c965cb1b92237ccf30 to your computer and use it in GitHub Desktop.
Save Wolvereness/a13982175fbc25c965cb1b92237ccf30 to your computer and use it in GitHub Desktop.
use std::cell::Cell;
#[derive(Default)]
struct Wrapper(Cell<usize>);
impl Wrapper {
fn increment_and_get(&self) -> usize {
let &Wrapper(ref cell) = self;
cell.replace(cell.get() + 1)
}
}
fn main() {
let obj: Wrapper = Default::default();
print_both(obj.increment_and_get(), obj.increment_and_get());
}
fn print_both(left: usize, right: usize) {
println!("({}, {})", left, right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment