Rust の Struct で mutable な field

Rubyのインスタンス変数的なやつをやりたかった。 use std::cell::Cell; struct S { n: usize, cnt: Cell<i64>, } impl S { fn f(&self) { for _ in 0..self.n { self.cnt.set(self.cnt.get() + 1); } } } fn main() { let s = S { n: 10, cnt: Cell::new(0), }; s.f(); println!("{}", s.cnt.get()); } こういう感じに深さ優先</i64>…