| I would be really careful with those deref methods. They return references, not pointers, which means you need to follow the Rust rules: - You can have any number of simultaneous readers, - Or one writer and no readers. - But if you ever break these rules, the world may burn. Using unsafe and violating these rules is one of the cases where the Rust compiler can inflict worlds of misery: Incorrect code generation, CPUs seeing different versions of the same memory location, etc., depending on the exact context. Once you use "unsafe" and break the rules, Rust can be more dangerous than C. Rust even reserves the right to generate code using "noalias" (except doing so often triggers LLVM bugs, so it's usually turned off). "Undefined behavior" means "anything at all can happen, and some of it is deeply weird and awful and counterintuitive." You could enforce the borrowing rules at runtime by using std::cell::Cell in your heap objects, which is exactly what it exists for. Or you could package everything inside a tiny core module and audit it extremely carefully. |