Medium
Cell<T> vs. RefCell<T> for interior mutability
What happens when this program is compiled and run?
main.rs
use std::cell::{Cell, RefCell};
struct Stats {
hits: Cell<i32>,
log: RefCell<Vec<i32>>,
}
fn main() {
let stats = Stats { hits: Cell::new(0), log: RefCell::new(Vec::new()) };
stats.hits.set(stats.hits.get() + 1);
stats.log.borrow_mut().push(stats.hits.get());
println!("hits = {}, log = {:?}", stats.hits.get(), stats.log.borrow());
}27 of 53 in Rust