#stack-trace #borrow #refcell #error #dynamic #failure #borrowing

accountable-refcell

A RefCell wrapper that provides actionable information for dynamic borrow failures

3 unstable releases

Uses old Rust 2015

0.2.1 Dec 11, 2020
0.2.0 Jan 6, 2020
0.1.0 Nov 2, 2017

#864 in Rust patterns

Download history 1385/week @ 2024-07-22 1791/week @ 2024-07-29 1882/week @ 2024-08-05 4112/week @ 2024-08-12 2216/week @ 2024-08-19 3128/week @ 2024-08-26 2912/week @ 2024-09-02 2781/week @ 2024-09-09 1865/week @ 2024-09-16 1909/week @ 2024-09-23 1948/week @ 2024-09-30 3861/week @ 2024-10-07 2541/week @ 2024-10-14 3079/week @ 2024-10-21 2482/week @ 2024-10-28 2648/week @ 2024-11-04

10,991 downloads per month
Used in 2 crates (via stylo_malloc_size_of)

MPL-2.0 license

17KB
386 lines

Accountable RefCell

This crate wraps the standard library's RefCell type while making it easier to deal with dynamic borrow failures. Each immutable or mutable borrow of the cell records the stack trace of the code that performed the borrow, and this record is destroyed when the borrow ends. In the event of a dynamic borrow failure (either a mutable borrow while there are outstanding immutable borrows, or an immutable borrow while there is an outstanding mutable borrow), the conflicting stack traces will be printed to stderr if the RUST_BACKTRACE environment variable is present.

Example (two outstanding immutable borrows when a mutable borrow is attempted):

Outstanding borrows:
   1: _$LT$accountable_refcell..RefCell$LT$T$GT$$GT$::borrow::h93de6dc5716214a2
   2: accountable_refcell::tests::cannot_borrow_mutably_multi_borrow::hd9184755b4f98dae
   3: _$LT$F$u20$as$u20$test..FnBox$LT$T$GT$$GT$::call_box::h30f93c5e44004cdd (.llvm.6B7221EB)
   4: __rust_maybe_catch_panic
   5: std::sys_common::backtrace::__rust_begin_short_backtrace::ha384908c78afca63
   6: std::panicking::try::do_call::h7da6a9b8bfb2762c (.llvm.E1945E4B)
   7: __rust_maybe_catch_panic
   8: _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::hd53410bd165f5d82 (.llvm.B1C468B7)
   9: std::sys::imp::thread::Thread::new::thread_start::hf16f292ea51f5fa0
  10: _pthread_body
  11: _pthread_start

   1: _$LT$accountable_refcell..RefCell$LT$T$GT$$GT$::borrow::h93de6dc5716214a2
   2: accountable_refcell::tests::cannot_borrow_mutably_multi_borrow::hd9184755b4f98dae
   3: _$LT$F$u20$as$u20$test..FnBox$LT$T$GT$$GT$::call_box::h30f93c5e44004cdd (.llvm.6B7221EB)
   4: __rust_maybe_catch_panic
   5: std::sys_common::backtrace::__rust_begin_short_backtrace::ha384908c78afca63
   6: std::panicking::try::do_call::h7da6a9b8bfb2762c (.llvm.E1945E4B)
   7: __rust_maybe_catch_panic
   8: _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::hd53410bd165f5d82 (.llvm.B1C468B7)
   9: std::sys::imp::thread::Thread::new::thread_start::hf16f292ea51f5fa0
  10: _pthread_body
  11: _pthread_start

thread 'tests::cannot_borrow_mutably_multi_borrow' panicked at 'RefCell is already immutably borrowed.', src/lib.rs:170:12

The public API of this crate's RefCell types mirrors the public API of std::cell::RefCell.

Dependencies

~2.3–7.5MB
~67K SLoC