better-refcell 0.1.1

A drop-in replacement for RefCell with safe unborrow and reborrow capabilities.
Documentation
  • Coverage
  • 100%
    21 out of 21 items documented3 out of 21 items with examples
  • Size
  • Source code size: 34.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.54 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • haruleekim/better-refcell
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • haruleekim

BetterRefCell

License Version Docs.rs CI

A drop-in replacement for RefCell with safe unborrow and reborrow capabilities.

Features

  • Allows putting back a borrowed value and reborrowing it within a closure.
  • Fully compatible with the RefCell interface of the stable Rust standard library.
  • Zero dependencies.

Usage

use better_refcell::BetterRefCell;
use std::cell::*;

let cell = BetterRefCell::new(42);

let mut guard: RefMut<i32> = cell.borrow_mut();
let mut_reference: &mut i32 = &mut *guard;

let ret = cell.unborrow(mut_reference, || {
    let mut guard = cell.borrow_mut();
    assert_eq!(*guard, 42);
    *guard += 1;
    format!("Returns {guard}")
});

assert_eq!(*guard, 43);
assert_eq!(ret, "Returns 43");

License

This project is dual-licensed under either the MIT or Apache-2.0 license, at your option.