4 ms·
When I hear sharing I think of shared ownership, and Rust steers you strongly away from that. See for example the awkwardness of global or thread-local variable
by millstone 10y ago
When I hear sharing I think of shared ownership, and Rust steers you strongly away from that. See for example the awkwardness of global or thread-local variables in Rust.
If you are referring to borrowing, Swift's answer is not class types, but inout. inout is not as flexible as Rust references, but it does not use reference counting. In most places where a Rust function would return a mutable reference, the analogous Swift function would take a closure that accepts that something as an inout.
- Manishearth 10y agoRight, I refer to the concept of sharing data without necessarily involving shared ownership. I am aware of inout, but like you said it's not as flexible. I find myself reaching for class types in Swift a lot more than in Rust. inout works for sharing that is extremely local, but more complicated sharing in larger codebases is hard.