'Make Your Rust Code More Rustic By Breaking Some Rules' terminal opensource
RefCell
uses reference counting to track how many borrows are active while the program is running. If you ever try to take a mutable reference and another reference at the same time,, it’s up to you to make sure that your program doesn’t try to read and write the same data at the same time.to cache intermediate results for something that is otherwise immutable:
struct FibonacciCalculator { cache: RefCell>, } impl FibonacciCalculator { /// Calculate the Nth fibonacci number, caching the result to prevent recalculation /// Note that this takes `&self`, not `&mut self`! fn calculate -> usize { // Base case if n >If you’re interested in breaking more of Rust’s rules and pushing the terminal into the future,