3 ms·
Yes, of course you can express this in rust. The topic at hand is whether it can be expressed in terms of rust's ownership policies. Your example shows that i
by moonchild 5y ago
Yes, of course you can express this in rust. The topic at hand is whether it can be expressed in terms of rust's ownership policies. Your example shows that it cannot; it returns an object of static lifetime, avoiding the issue completely.
- littlestymaar 5y agoThe topic at hand was about the comparison between C and Rust in terms of memory model. Ownership policies are one restriction safe Rust uses to ensure that the user is adhering to its memory model, but Rust is not limited to safe Rust and you can op-out ownership policies if you use raw pointers. The difference between Rust and C in terms of memory model isn't ownership, it's “mutable xor shared”.
- drran 5y agoI cannot understand your question about "ownership policies". Rust have only one ownership policy: one owner per object. It's possible to use pointers to circumvent the restriction and then control when object is destructed using ManuallyDrop[0], so burden of memory bookkeeping will be shifted from Rust compiler to the programmer. [0]: https://doc.rust-lang.org/core/mem/struct.ManuallyDrop.html https://doc.rust-lang.org/core/mem/struct.ManuallyDrop.html