Hacker News new | ask | show | jobs
by actuallyalys 1422 days ago
Good point. This is a case where the problem may be in part people's preconceptions about how Rust "should" be used. People sometimes feel like cloning or using references is somehow cheating, but I think if people let go of that idea, it would be natural for them to choose a Rc<RefCell<T>> for these long running operations, as it mimics what GC'd or RC'd languages do.

I wonder if this error could be preventable by Rust's type system so that you can't have indexes that fall out of sync with the underlying Vec. It definitely wouldn't be backward compatible, so it would have to a new type built on Vecs. Although like another reply to your comment points out, keeping indexes is unidiomatic (in many languages) and would probably cause other bugs, which would hopefully prompt a developer to rethink it, so maybe an abstraction on top of Vec isn't needed.