3 ms·
Yes, but that's kind of the point: Rust's borrow checker only really works for data-ownership graphs that are trees, and although it does pretty well for that u
by thristian 8y ago
Yes, but that's kind of the point: Rust's borrow checker only really works for data-ownership graphs that are trees, and although it does pretty well for that use-case, it's not perfect and research continues on how to make it less conservative while still being safe (consider the non-lexical-lifetimes feature arriving in a near-future release of Rust). A static borrow-checker that works for directed-acyclic or even cyclic ownership graphs would be wonderful, but that's definitely an open research topic, not a production-quality-compiler topic.
So if you can't prove your ownership graph is safe at compile time, you have to do it at runtime. For some ownership graphs, reference counting with Rc<T> is the right choice, but in the general case indexes and vectors are the least-verbose way to represent a runtime ownership graph.