3 ms·
It's fundamental to rust's view of ownership and borrowing of data. It's not just strings, but it's everything. Strings represent a single exclusive owner of
by bvinc 9y ago
It's fundamental to rust's view of ownership and borrowing of data. It's not just strings, but it's everything. Strings represent a single exclusive owner of mutable data. &str represents one of possibly many read-only shared references to the internal data of a string.
Once you understand this concept you see it over and over. It's how every type in the language works (unless that type implements the Copy trait).
I actually think this is something really fundamental and amazing the more I think about it. Most languages, like Java, tell you to make defensive copies of your data because you never know who will be modifying it later. Also most languages will enforce that all strings are always immutable, to prevent people from needing to make defensive copies. Rust just naturally handles this with it's ownership and borrowing rules. And then the very same concept is what makes concurrency safe.
- mamcx 9y agoYeah I get this, but still is very hard cliff. "String" is so fundamental and when you see how operate with ints, floats and sudenly strings is a hard climb. In the mind of many, strings are at the same "level" than other primitives. I wish it have a "easy mode" and a "advanced" one for when is necessary.