Skip to content

Add recipe: interior mutability with Cell #835

Description

@AndyGauge

Add a recipe demonstrating std::cell::Cell for Copy types — get/set/replace/take — and contrast it with the existing Rc<RefCell<T>> recipe: Cell avoids runtime borrow checking and panics by never handing out references, at the cost of only working by-value.

Cell is core/std only, so this fits as an inline skeptic example (Pattern 1) with no new dependency, likely alongside the existing recipes in src/mem/smart_pointers.md. Originally requested in #434 under "Rust patterns".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions