BorrowError
BorrowError is a runtime error type defined in the Rust standard library, specifically in the core::cell module. It is produced by the RefCell<T> type when an attempt is made to borrow the contained value in a way that violates the cell's borrowing rules. RefCell implements Rust’s interior mutability pattern, allowing values to be borrowed mutably or immutably at runtime rather than at compile time. BorrowError is returned by the try_borrow() and try_borrow_mut() methods of RefCell and the associated try_borrow methods on the Ref and RefMut types.
The error contains a boolean flag, called `mutably_borrowed`, that indicates whether the failure was due to an
Typical causes of a BorrowError include calling RefCell::try_borrow_mut() while two immutable borrows are active, or calling
BorrowError is distinct from the compile‑time borrow checker errors that Rust normally generates. While the compiler