Safety
Rune is written in Rust, but parts of the runtime use unsafe code. This
section documents the main unsafe components, why they exist, and the
invariants they rely on.
Internal Any type
Rune uses an internal Any type (AnyObj) rather than Box<dyn Any> so that
type metadata and vtables can represent both Rust types and external types
(such as across a C FFI boundary). Type identity relies on deterministic 64-bit
type hashes.
Shared<T> and UnsafeToRef / UnsafeToMut
A large part of the Shared<T> container is implemented with unsafe.
Behaviorally, Shared<T> is similar to Rc<RefCell<T>>.
Rune uses a custom container to combine reference counting with dynamic borrow
checking, support “owned borrows”, and decompose a borrow into a raw pointer
and guard for UnsafeToRef and UnsafeToMut.
UnsafeToRef and UnsafeToMut are internal conversion traits used when
calling native functions with borrowed arguments. Their safety contracts are
documented on the traits themselves.