
Getting Started with Rust: Reference and Lifetime - mnivoliez
https://www.mathieu-nivoliez.com/posts/2018-03-05-getting-started-with-rust-reference-and-lifetime.html
======
squiguy7
> I may express here a crucial point, LIFETIMES ARE HARD TO DEAL WITH, so try
> to not use them to often.

While this can be true, you are always dealing with them if you have a
reference to something. Sometimes the compiler will elide them for you but
other times you need to explicitly write them. The code snippets in this blog
need lifetime annotations for example.

~~~
mamcx
I have found harder to use Strings. I start build a little interpreted
language and boom! the strings is the roadblock.

I still not figure what the hell is the deal with it. Why rust no "just" give
a "string for mortals"?

~~~
bvinc
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
Yeah 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.

