Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 9, 2019 13:47
Show Gist options
  • Save rust-play/b3dec1c32f1b0d21720ef185bf464960 to your computer and use it in GitHub Desktop.
Save rust-play/b3dec1c32f1b0d21720ef185bf464960 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![allow(dead_code)]
use std::cell::RefCell;
#[derive(Debug)]
struct Ctx {
mult: i32,
items: RefCell<Vec<i32>>,
}
fn work(x: &Ctx, i: &mut i32) {
*i = *i * x.mult;
}
fn simplework(x: &i32, i: &mut i32) {
*i = *i * x;
}
fn proc(x: &Ctx) {
let mut items = x.items.borrow_mut();
for item in items.iter_mut() {
//work(x, item);
simplework(&x.mult, item);
}
}
fn main() {
let x = Ctx{mult: 100,
items: RefCell::new(vec!(1, 2, 3))};
proc(&x);
println!("{:?}", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment