Created
October 9, 2019 13:47
-
-
Save rust-play/b3dec1c32f1b0d21720ef185bf464960 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
#![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