3 ms·
Most of the time, Rust's ownership system is helpful. Sometimes, it's a pain though. In these cases, you can actually work around the ownership system if you ne
by conradk 12y ago
Most of the time, Rust's ownership system is helpful. Sometimes, it's a pain though. In these cases, you can actually work around the ownership system if you need too.
For instance, you can use Arc [1] to share memory between threads or Rc [2] to enable thread local GC for a specific variable or RefCell [3] to safely share mutable memory between threads. You can even use raw pointers: it's unsafe (and therefore has to be wrapped in an "unsafe { ... }" block) but possible. Finally, you can call C very easily from Rust [4].
[1] http://doc.rust-lang.org/std/sync/struct.Arc.html http://doc.rust-lang.org/std/sync/struct.Arc.html
[2] http://doc.rust-lang.org/std/rc/struct.Rc.html http://doc.rust-lang.org/std/rc/struct.Rc.html
[3] http://doc.rust-lang.org/std/cell/struct.RefCell.html http://doc.rust-lang.org/std/cell/struct.RefCell.html
[4] http://doc.rust-lang.org/book/ffi.html http://doc.rust-lang.org/book/ffi.html