Hacker News new | past | comments | ask | show | jobs | submit login

> But if you use RefCell, then you won't get any useful compile-time checks, will you?

If you use RefCell, then the compile-time checks won't be necessary. For example, in Java there are no compile-time checks: everything is just garbage-collected at runtime. Likewise, RefCell is lightweight garbage-collection (modulo cyclic references).

> In other words: if you have Rust _without_ unsafe and without RefCell (and similar stuff), will you still be able to implement anything in it and keep compile-time checks and other benefits of ownership system?

Ah, in that case there are a lot of things you can't implement: Strings, doubly-linked lists (which is the point of this article), trees with backpointers, graphs, vectors, etc. Fortunately, you rarely need to: if you need a data structure, it's probably already implemented in Rust. The standard library has most common data structures, and there are often crates for less common ones. If you do need to write unsafe Rust, it's about as scary as C. I've written a reasonable amount of Rust code, and only ran into one situation where I (think) I need unsafe code.




You’re confusing Rc and RefCell, RefCell is “borrow checking at runtime”, Rc is “lightweight garbage collection”.


Aaagh, yes! I meant Rc everywhere :-(.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: