better-refcell 0.1.1

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

[![License](https://img.shields.io/crates/l/better-refcell)](https://github.com/haruleekim/better-refcell#License)
[![Version](https://img.shields.io/crates/v/better-refcell.svg)](https://crates.io/crates/better-refcell)
[![Docs.rs](https://img.shields.io/docsrs/better-refcell?logo=docsdotrs)](https://docs.rs/better-refcell)
[![CI](https://img.shields.io/github/actions/workflow/status/haruleekim/better-refcell/ci.yaml?event=push&logo=github)](https://github.com/haruleekim/better-refcell/actions/workflows/ci.yaml)

<!-- cargo-rdme start -->

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

```rust
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");
```

<!-- cargo-rdme end -->

## License

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